Skip to content

Add save and load methods to Project, Controls and Results #122

@alexhroom

Description

@alexhroom

further to discussion in RascalSoftware/RAT-Docs#24, we should add consistent save and load methods to the Project, Controls and Results classes. The current interface is:

from pathlib import Path

# save project
Path("./project.json").write_text(project_to_json(my_project_class))
#load project
project_from_json(Path("./project.json").read_text())

# save controls
Path("./controls.json").write_text(my_controls_class.model_dump_json())
# load controls
Controls.model_validate_json(Path("./controls.json").read_text())

# save and load results
# I don't think this is currently possible? results isn't pickleable or JSON serialisable

this should be replaced with a consistent interface, e.g.:

my_project_class.save("./project.json")
Project.load("./project.json")

my_controls_class.save("./controls.json")
Controls.load("./controls.json")

my_results.save("./results.json")
Results.load("./results.json")

which is easier to remember, far more consistent, doesn't require the user to learn anything about Pydantic, and is quite similar to the MATLAB interface (with some changes as we are using json format for projects and controls rather than some kind of direct serialisation like .mat/pickle)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions