bloc.calc_note#
Automated Calculation Note generation from YAML export configuration.
This module provides generate_calculation_note(), which reads the export
section of a base YAML file to determine which scenarios to run and then
produces an Excel Calculation Note with side-by-side scenario columns,
embedded diagrams, and structured metadata.
Typical usage from a run script:
from bloc.calc_note import generate_calculation_note
generate_calculation_note(base_yaml=yml_file, module=module)
Functions#
|
Run scenarios and generate an automated Calculation Note (Excel). |
|
Run STONE scenarios and generate Calculation Note Excel. |
Module Contents#
- bloc.calc_note.generate_calculation_note(base_yaml, module=None, output_dir='Results', extra_yamls=None, *, backend='ctwrap', kpi_fn=None, validate_strict=False)#
Run scenarios and generate an automated Calculation Note (Excel).
This is the unified entry point for Bloc’s Calculation Note generation. Two backends are supported:
backend="stone"(recommended) — YAML-only path usingbloc.simulation_builder.build_simulation_from_yaml(); no Pythonmoduleneeded. Acceptskpi_fnandvalidate_strictand forwards them togenerate_calculation_note_stone().backend="ctwrap"(deprecated) — legacy path that drives actwrapsimulation module. Requires themoduleargument. Emits aDeprecationWarning. Port to STONE usingdocs/migration_guide.mdand switch tobackend="stone".
The function reads the
exportsection of base_yaml to configure the report. Recognised keys insideexport:calc_note– output Excel filename (default:<stem>_Calculation_Note.xlsx)title– report title rowsubtitle– report subtitle rowmain_species– number of top species by mole fraction (default 8, gas-phase only)main_species_mass– number of top species by mass fraction (default 6, gas-phase only)minimum_mole_fraction_balance– include species until cumulative mole fraction >= this (0–1, default 0.95); use 0 to disableminimum_mass_fraction_balance– include species until cumulative mass fraction >= this (0–1, default 0.95); use 0 to disablemandatory_species– species that must always appearminimum_hydrogen_balance– target H balance threshold (0–1, default 0.95); species are added in descending order of H-atom contribution until the cumulative sum accounts for at least this fraction of total inlet Hminimum_carbon_balance– target C balance threshold (0–1, default 0.95); same logic asminimum_hydrogen_balancebut for carbon atomsreactor_kind– selects the variable-map set; supported values:"TubeFurnace"(TF maps frombloc.yaml_utils); omit or leave blank for the default SPRING maps.
Minimal export section example:
export: calc_note: "MyProject_Calculation_Note.xlsx" title: "Hydrogen Production Analysis" subtitle: "Baseline vs. Optimized Configuration"
- Parameters:
base_yaml (
strorPath) – Absolute or relative path to the base YAML configuration file.module (
module, optional) – Imported simulation module (frombloc.batch.import_simulation()). Required whenbackend="ctwrap"; ignored whenbackend="stone".output_dir (
str) – Sub-directory (relative to base_yaml’s parent) for output files.extra_yamls (
str,list[str], orNone) – YAML files to use as overlay scenarios. Can be: - A glob pattern (e.g.,"SPRING_A3_BG_20260212_gen*.yaml") - A list of file paths or glob patterns - None (default): only the base scenario is run (no overlay scenarios).backend (
{"stone", "ctwrap"}) – Which simulation backend to use (see above). Prefer"stone";"ctwrap"is deprecated and will be removed in a future release.kpi_fn (
callable, optional) – STONE-only; forwarded togenerate_calculation_note_stone().validate_strict (
bool) – STONE-only; forwarded togenerate_calculation_note_stone().
- Returns:
Path to the generated Excel file, or None if no
exportsection was found in the YAML.- Return type:
PathorNone- Raises:
None – If no
exportsection is present in the YAML, the function returns None without raising an error.
- bloc.calc_note.generate_calculation_note_stone(base_yaml, output_dir='Results', extra_yamls=None, scenario_yamls=None, include_base=True, validate_strict=False, kpi_fn=None)#
Run STONE scenarios and generate Calculation Note Excel.
Uses
bloc.simulation_builder.build_simulation_from_yaml()for each scenario (base + overlays). Validates YAML withvalidate_yaml_file()(no strict unit check for STONE). Writes the same Excel format asgenerate_calculation_note().- Parameters:
base_yaml (
strorPath) – Path to the base STONE YAML (e.g. SPRING_A3_BG_20260212_stone.yaml).output_dir (
str) – Output directory relative to the YAML parent.extra_yamls (
strorlist[str]orNone) – Glob pattern(s) for overlay STONE YAMLs (e.g. “_stone.yaml”). Deprecated — prefer declaring variations inline in the base YAML viascenarios:orsweeps:(seebloc.yaml_utils.expand_scenarios()). Combining inline scenarios withextra_yamlsis rejected.scenario_yamls (
strorlist[str]orNone) – Standalone scenario YAML files/patterns to run and aggregate into the same workbook. Supports files usingfrom: master.yamlinheritance. Unlikeextra_yamls, these files are not deep-merged ontobase_yaml; each is treated as a complete scenario definition.include_base (
bool) – If True, run the base YAML as a scenario in addition to inline/standalone scenarios. If False, base is used only as workbook/export template.validate_strict (
bool) – If True, raise on any YAML validation issue.kpi_fn (
callableorNone) – Optionalkpi_fn(sim) -> dictthat computes domain-specific KPIs from each solvedSimulation. Its output is merged into theoutputscolumn of the Calculation Note. Equivalent to settingexport.kpi_fn: "module:attr"in the YAML; specifying both is ambiguous and raisesValueError. Usebloc.spring_kpi.compute_spring_kpis()for SPRING architectures.
Notes
The STONE
export:block also accepts:kpi_fn— dotted path ("module:attr") resolved viabloc.yaml_utils.resolve_dotted().figures— list of keys intobloc.yaml_utils.STONE_FIGURE_GENERATORS. Each generator has signature(sim, out_dir) -> dict[str, str].
- Returns:
Path to the generated Excel file, or None if base YAML has no metadata.
- Return type:
PathorNone