PinchProblem
OpenPinch.classes.pinch_problem.PinchProblem is the primary
single-case interface in the package. It owns the source inputs, validated
problem data, prepared zone tree, solved targets, graph exports, stateful
reruns, and several advanced post-processing helpers.
When To Use It
Use PinchProblem when you want:
support for JSON, workbook, CSV-bundle, packaged sample-case, or in-memory inputs
one object that keeps both the original case and the solved result state
compact and detailed summary tables
graph building and graph export without manually wiring result payloads
notebook-friendly advanced workflows such as HPR screening or
dt_contsensitivity studiesselected-state reruns through
state_idand batch reruns throughtarget_all_states()
Use PinchWorkspace instead when the study itself needs to keep multiple named cases and compare them over time.
Supported Sources
PinchProblem accepts these load shapes:
TargetInputor plain mappingsJSON files
Excel files such as
.xlsxand.xlsba directory with
streams.csvandutilities.csva
(streams_csv, utilities_csv)tuplea packaged sample-case name such as
basic_pinch.jsonwhen no local file with that name exists
Lifecycle
The typical lifecycle is:
construct the wrapper with a project name or input source
call
load()or pass the source at construction timecall
validate()if you want a preflight checkcall
target()inspect summaries, graphs, exports, state-specific reruns, or the prepared
master_zone
When the source is a bare *.json filename and no local file exists,
PinchProblem also resolves packaged sample cases such as
basic_pinch.json or crude_preheat_train.json directly.
Core Workflow Members
The main user-facing workflow members are load(), validate(),
target(), summary_frame(), export_excel(), compare_to(),
set_dt_cont_multiplier(), update_options(), target_all_states(),
and show_dashboard().
Stateful Workflows
When the prepared data contains multiple states, the main stateful surfaces are:
state_idsfor the canonicalstate_id -> idxmappingnamed
problem.target.*(..., state_id="peak")rerunstarget_all_states(parallel=False | True | "thread" | "process")for batch solves across every canonical state
State selection happens at targeting time, not at load time. The cached result, summary frame, export surface, and graph payload then reflect the selected state.
Advanced Entry Points
Two descriptor families make PinchProblem broader than a simple wrapper:
problem.plotBuilds Plotly figures for composite curves, grand composite curves, net-load profiles, and related graph families from the cached solved state.
problem.targetRe-runs targeted advanced routines such as direct and indirect heat pump, refrigeration, cogeneration, or area/cost targeting against the prepared zone hierarchy. Named target workflows also accept
state_id=...when a input data carries stateful values, and the refreshed summary/export surfaces then expose that selected state on the result rows.
Named target methods also accept zone_name=... and
include_subzones=True when you want one zone-level or subtree-level rerun
instead of the default root-case solve.
Those accessors are the high-level path into the package’s deeper analytical power without dropping all the way to the raw service modules.
Output and Inspection Surfaces
After solving, the main read and export surfaces are:
summary_frame()for compact or detailed pandas viewsproblem.plot.catalog()for the available graph inventoryproblem.plot.*for Plotly figures and raw graph payloadsproblem.plot.export(...)for standalone HTML graph filesexport_excel(...)for workbook outputshow_dashboard()for the Streamlit-based review surface
PinchProblem API
- class OpenPinch.classes.pinch_problem.PinchProblem(source=None, *, project_name='Site')[source]
Bases:
objectTyped orchestrator for loading input data and running targeting.
- Parameters:
source (TargetInput | JsonDict | PathLike | tuple[PathLike, PathLike] | None)
project_name (Optional[str])
- load(source=None)[source]
Load problem inputs from JSON, Excel, CSV, or an in-memory object.
- property state_ids: dict[str, int]
Return the canonical
state_id -> idxlookup for the loaded problem.
- target_all_states(*, parallel=False, max_workers=None, preserve_cached_results=True)[source]
Run default targeting once per canonical state id.
- Parameters:
parallel (bool | str) –
Falseruns serially.Trueand"process"use a process pool, while"thread"uses a thread pool which is suitable for no-GIL Python builds.max_workers (int | None) – Optional executor worker limit for parallel runs.
preserve_cached_results (bool) – Restore the original
resultscache after the batch run whenTrue.
- Return type:
- validate()[source]
Validate the currently loaded problem data without running targeting.
- Return type:
- summary_frame(*, detailed=False)[source]
Return the solved target summary as a pandas DataFrame.
- export_excel(results_dir=None)[source]
Export the solved target summary and problem tables to an Excel file.
- compare_to(other_problem, *, target_name=None, base_label='Base case', other_label='Scenario')[source]
Compare the compact summaries of two solved problems.
- Parameters:
other_problem (PinchProblem)
target_name (str | None)
base_label (str)
other_label (str)
- Return type:
- property problem_filepath: Path | None
Return the filepath of the problem that was loaded or supplied.
- property problem_data: Dict[str, Any] | TargetInput | None
Return the raw problem definition that was loaded or supplied.
- property results: TargetOutput | None
Return the cached targeting results, if targeting has been executed.
- property hot_streams: StreamCollection
Hot process streams on the root analysis zone.
- property cold_streams: StreamCollection
Cold process streams on the root analysis zone.
- property hot_utilities: StreamCollection
Hot utility streams on the root analysis zone.
- property cold_utilities: StreamCollection
Cold utility streams on the root analysis zone.
- property project_name: str
Return the project label used for the root zone and exports.
- classmethod from_json(data)[source]
Build from an in-memory mapping and apply the normal input cleaners.
- Parameters:
- Return type:
- to_problem_json(*, canonical=False)[source]
Return the currently loaded problem inputs.
- canonical_problem_json()[source]
Return canonical mutable problem inputs with an explicit zone tree.
- set_dt_cont_multiplier(value, *, zone_name=None)[source]
Update one zone-tree multiplier and rebuild the prepared analysis state.
- update_options(options, *, replace=False)[source]
Update the problem options in-place and rebuild the analysis state.
Heat Pump Integration Comparison
Older examples sometimes refer to broader helper-backed HPR comparison flows.
The current object surface instead exposes the explicit advanced HPR routines
on problem.target.*, described above and in Service Layer.
Relationship To Lower Layers
PinchProblem is a wrapper, not a separate solver. Under the hood it still
validates the input data, prepares a Zone tree,
runs the same targeting services documented in Service Layer, and then
packages the outputs for summaries, graphs, and export.
If you need to mutate the prepared zone tree directly, inspect stream objects, or run only one analysis stage, move down to Service Layer and Domain Model.