Skip to content

Refactor main script#9

Merged
Ickaser merged 31 commits intoLyoHUB:mainfrom
Ickaser:main-function
Feb 13, 2026
Merged

Refactor main script#9
Ickaser merged 31 commits intoLyoHUB:mainfrom
Ickaser:main-function

Conversation

@Ickaser
Copy link
Member

@Ickaser Ickaser commented Dec 19, 2025

As a step towards making the web interface of LyoPRONTO easier to update, refactor the main.py so that the bulk of the logic is encapsulated inside LyoPRONTO as a package.

Some things still to document, and possibly some more to add as kwargs. This should get rebased to add unit tests from #6 , so that I have actually kept the old API.

This does introduce a possibly-breaking change of replacing 'Y' and 'N' strings with True and False, which feels like a no-brainer to me. Other aspects of the API are kept constant, I think.

Still would like to add a YAML representation of the input parameters, to replace the current CSV representation.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the previous main.py “script-style” workflow into a reusable high-level API under lyopronto (with YAML-based inputs/outputs), and adds integration-style tests + example YAML fixtures to validate the refactor.

Changes:

  • Introduces lyopronto.high_level with execute_simulation, YAML input read/write, CSV export, and visualization generation.
  • Updates main.py to delegate to the high-level API and switches legacy Y/N flags to booleans.
  • Adds “fullstack” pytest coverage for the former main.py behavior and adds YAML fixtures in test_data/.

Reviewed changes

Copilot reviewed 22 out of 24 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
lyopronto/high_level.py New high-level API wrapper for running tools, saving/loading inputs, exporting CSVs, and plotting.
lyopronto/__init__.py Re-exports high-level API functions at package root for from lyopronto import *.
main.py Refactored to build an inputs dict and call the package high-level API instead of inlining logic.
lyopronto/plot_styling.py Refactors plotting style helpers to reduce duplication and centralize defaults.
lyopronto/design_space.py Adds return-shape documentation; preserves existing design space computation behavior.
lyopronto/functions.py Refactors/renames config tuple usage in primary drying output generation; adjusts crystallization timing logic.
lyopronto/calc_knownRp.py Updates callsites to use the renamed inputs tuple passed into fill_output.
tests/test_main.py New end-to-end tests for the high-level API (I/O + simulation + plotting).
tests/test_design_space.py Updates assertions to match design space outputs as stacked arrays with explicit shapes.
tests/test_calc_knownRp.py Adds coverage that the high-level API dispatches into calc_knownRp.dry as expected.
tests/test_calc_unknownRp.py Adds coverage that the high-level API dispatches into calc_unknownRp.dry as expected.
test_data/example_freezing.yaml New YAML fixture for freezing tool inputs.
test_data/example_knownrp.yaml New YAML fixture for known-Kv/Rp primary drying inputs.
test_data/example_unknownkv.yaml New YAML fixture for unknown-Kv primary drying inputs.
test_data/example_unknownrp.yaml New YAML fixture for unknown-Rp primary drying inputs (with external temperature file reference).
test_data/example_design_space.yaml New YAML fixture for design space tool inputs.
test_data/example_opt_tsh.yaml New YAML fixture for optimizer (variable shelf temperature) inputs.
test_data/example_opt_pch.yaml New YAML fixture for optimizer (variable chamber pressure) inputs.
test_data/example_opt_pch_tsh.yaml New YAML fixture for optimizer (variable chamber + shelf) inputs.
test_data/badexample_unknownkvrp.yaml New negative-test YAML fixture (neither Kv nor Rp known).
test_data/badexample_optimizer_noopt.yaml New negative-test YAML fixture (optimizer with no variable decision).
pyproject.toml Adds ruamel.yaml to runtime deps, pytest-mock to dev deps, and a main marker.

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

Comment on lines +3 to +4
from contextlib import chdir
import pytest
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

from contextlib import chdir is only available on Python 3.11+, but pyproject.toml declares support for Python >= 3.8. This will raise ImportError on 3.8–3.10. Prefer using monkeypatch.chdir(tmp_path) (pytest) or a small local context manager based on os.chdir to keep the tests compatible with the supported Python range.

Copilot uses AI. Check for mistakes.
@Ickaser Ickaser requested a review from Copilot February 9, 2026 19:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Ickaser
Copy link
Member Author

Ickaser commented Feb 9, 2026

Will close #11.

Remaining (possible) to-do items: add more keyword arguments to the basic plotting method, or come up with more documentation showing how to customize directly with matplotlib.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 12 comments.


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

@Ickaser
Copy link
Member Author

Ickaser commented Feb 9, 2026

Going to give myself a day or two to stew on this, but otherwise I think this is ready to merge.

Along with changing "Y" and "N" to True and False, this also changes the tool name from "Design-Space-Generator" (with hyphens) to "Design Space Generator" (with spaces). Arguably that is also breaking, but it was also inconsistent with the other three tool names and the API was always fuzzy so I am going to move forward with it as is.

@Ickaser Ickaser merged commit 86c205c into LyoHUB:main Feb 13, 2026
3 checks passed
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.

1 participant

Comments