Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist local state between sessions (make separate Case.persist() and Case.to_blueprint() methods) #158

Open
5 tasks
dafyddstephenson opened this issue Oct 28, 2024 · 0 comments
Assignees

Comments

@dafyddstephenson
Copy link
Contributor

Issue:

Currently, there is no support for persisting C-Star objects in their current state between python sessions.

Example

If we run

Case.from_blueprint(blueprint="my_blueprint.yaml", caseroot=Path("my/dir"))
Case.setup()

Then Case.is_setup returns True as expected.
However, if you exit this session and run

Case.from_blueprint(blueprint="my_blueprint.yaml", caseroot=Path("my/dir"))
Case.is_setup

we now get False, even though nothing has changed on the filesystem. This is because the setup method also calls methods like get on InputDataset and AdditionalCode objects that set attributes like InputDataset.working_path that are related to the local state of the Case, but aren't relevant information to include in a blueprint file. These attributes are thus lost when exiting the session, unless the user runs Case.setup() again. The local working file associated with an InputDataset may be different to the source version (for instance, local netCDF generated from remote yaml), so the distinction between the source material (described in the blueprint) and the local state is nontrivial.

Proposed solution:

  • Rename the current Case.persist() method to Case.to_blueprint(). This is consistent with the existing Case.from_blueprint() complement method.
  • Add some sort of local_file_hash attribute that is set when get() is called on objects like InputDatasets and AdditionalCode. This becomes part of the state to be reloaded and can verify that files on disk have not changed between sessions
  • Add an include_state=True/False parameter on the to_dict methods of fundamental classes. to_dict is used heavily by Case.persist() but currently just includes information for recreating the object from scratch (as is required for blueprint export), not restoring it to its current state.
  • Define a new Case.persist() that exports the entire local state to a {caseroot}/{case_name}_state.yaml file. This could be called automatically at the successful end of certain methods that update the state, like Case.setup()
  • Define a Case.restore(caseroot="wherever") method that looks in the caseroot for the state file and re-establishes the exact state that was persisted.
@dafyddstephenson dafyddstephenson self-assigned this Oct 28, 2024
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

No branches or pull requests

1 participant