Skip to content

Enhance Caller.py and CaseStudy with logging, error handling, and functions - #36

Merged
FelixCAAuer merged 30 commits into
mainfrom
feature/Frauental
Jul 30, 2026
Merged

Enhance Caller.py and CaseStudy with logging, error handling, and functions#36
FelixCAAuer merged 30 commits into
mainfrom
feature/Frauental

Conversation

@FelixCAAuer

Copy link
Copy Markdown
Contributor

This pull request introduces comprehensive documentation and several improvements to the InOutModule, clarifying both developer and user-facing aspects. It also adds minor code fixes and enhancements to data handling and the parallel job runner. The most important changes are summarized below.

Documentation and Maintenance Rules

  • Added .claude/rules/claude-md-maintenance.md to specify clear rules for updating CLAUDE.md and README.md after code changes, including guidance on avoiding duplication and maintaining up-to-date documentation for InOutModule.
  • Added a new CLAUDE.md with detailed architecture notes for Claude, documenting non-obvious design decisions, data flows, and implementation constraints for core modules like CaseStudy, ExcelReader, ExcelWriter, SQLiteWriter, and Caller.
  • Expanded and clarified README.md with a high-level overview, file index, API documentation for CaseStudy, usage examples for Caller and SQLiteWriter, and a description of the Excel input format.

New Features and Enhancements

  • Added a new Caller.py script: a robust parallel job runner supporting job barriers, per-job logging, error handling, and Windows terminal spawning. This tool enables batch execution and synchronization for experiments.

Bug Fixes and Data Handling

  • In ExcelReader.py, ensured index columns are always converted to strings in both pivoted and non-pivoted file readers to prevent subtle bugs with integer indices. [1] [2]
  • In SQLiteWriter.py, clarified the type annotation for model_to_sqlite to require a ConcreteModel, improving type safety.

Fix bug in calculating PowerWeights_RP
Add white text for sections which are otherwise too dark
@FelixCAAuer FelixCAAuer self-assigned this Jul 30, 2026
Copilot AI review requested due to automatic review settings July 30, 2026 22:45
@FelixCAAuer
FelixCAAuer merged commit 5c2ed2f into main Jul 30, 2026
2 checks passed
@FelixCAAuer
FelixCAAuer deleted the feature/Frauental branch July 30, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands InOutModule’s documentation and introduces several usability/robustness enhancements across the CaseStudy loader, SQLite export, utilities, and a new parallel job-runner (Caller.py).

Changes:

  • Added/expanded documentation (README.md, CLAUDE.md, and .claude/rules/…) describing architecture, APIs, and doc maintenance rules.
  • Added new functionality: a Caller.py parallel job runner, new transition-matrix plotting utility, and additional CaseStudy data-manipulation methods.
  • Hardened data handling: ensured Excel index columns are read as strings; updated SQLite export typing and solver-statistics recording.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Utilities.py Adds utility fixes and a new plot_transition_matrix() helper (introduces plotting dependency considerations).
SQLiteWriter.py Tightens model_to_sqlite typing and refactors solver-stat export to pull from a LEGO instance.
README.md Adds high-level docs, file index, CaseStudy API overview, and usage examples.
printer.py Adds note(), rule(), and timestamp() helpers.
ExcelReader.py Forces index columns to string for both pivoted and non-pivoted reads.
CLAUDE.md Adds architecture notes / design constraints for key modules.
CaseStudy.py Adds scenario filtering option, generator merge utilities, transition-matrix perturb/shift utilities, and refactors weight computation.
Caller.py New parallel job runner supporting barriers, per-job logs, and error handling (needs platform guards).
.claude/rules/claude-md-maintenance.md Adds doc maintenance rules specific to InOutModule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Utilities.py
import typing
from typing import TYPE_CHECKING, Literal, Dict

import matplotlib.pyplot as plt
Comment thread SQLiteWriter.py
Comment on lines 8 to 10
from InOutModule.printer import Printer
from LEGO.LEGO import LEGO

Comment thread CaseStudy.py
Comment on lines +228 to +234
if not self.do_not_filter_unused_scenarios:
self.dGlobal_Scenarios = self.dGlobal_Scenarios[self.dGlobal_Scenarios['relativeWeight'] != 0] # Drop rows in dGlobal_Scenarios where relativeWeight is 0
if len(self.dGlobal_Scenarios) == 0:
raise ValueError("No scenarios are present in the 'Global_Scenarios' table. Please check if the file exists and contains valid data.")
elif len(self.dGlobal_Scenarios) == 1:
self.filter_scenario(self.dGlobal_Scenarios.index[0], inplace=True) # Filter case study to only include actually present scenarios

Comment thread CaseStudy.py
Comment on lines +1211 to +1213
sc = hindex_flat[hindex_flat['scenario'] == scenario].copy()
sc = sc.sort_values(['p'])
n_ks_per_rp = len(self.dPower_WeightsK['scenario'] == scenario)
Comment thread Caller.py
Comment on lines +38 to +46
if args.spawn >= 1:
printer.information(f"Spawning {args.spawn} parallel jobs")
for i in range(args.spawn):
subprocess.Popen([
"cmd", "/c", "start", f"Caller {i}: {args.jobs}", "cmd", "/k",
f"set POST_ACTIVATE_COMMAND=python {os.path.abspath(__file__)} {args.jobs} && call Conda-Activation-Scripts/activate_environment_windows.bat"
])
printer.information(f"Spawned {args.spawn} parallel jobs, exiting... ")
exit(0)
Comment thread Caller.py
Comment on lines +119 to +121
printer.information(f"Executing job {i} from '{args.jobs}': {line.strip()}")
ctypes.windll.kernel32.SetConsoleTitleW(f"Job {i} from '{args.jobs}': {line.strip()}") # type: ignore[attr-defined] - it is Windows-only anyway, so we can ignore the fact that this attribute doesn't exist on other platforms

Comment thread Caller.py
Comment on lines +73 to +77
for i, line in enumerate(lines):
started_job_flag = f"{args.jobs}.started{i}"
finished_job_flag = f"{args.jobs}.finished{i}"
error_job_flag = f"{args.jobs}.error{i}"
if line.strip() == "---":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants