-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactor Python Model #512
Comments
visr
added
python
Relates to one of the Ribasim python packages
tech-debt
Improvements related to technical debt
labels
Aug 17, 2023
This was already started once by @SouthEndMusic. What also came up is to generate a JSONSchema for our TOML config file and use it like we use our nodes. |
visr
pushed a commit
that referenced
this issue
Sep 14, 2023
Fixes #512 - [x] Add JSON Schema of Config and generate Python code - [x] Autogenerate Pandera Schemas - [x] Update docs to include the above - [x] ~Refactor Python model into split Config & Root submodels~
evetion
added a commit
that referenced
this issue
Nov 14, 2023
Fixes #512 Groundwork for #630 & #252 The code has become much simpler in some places (e.g. write_toml). ```python from ribasim import Model m = Model(filepath="generated_testmodels/basic/ribasim.toml") m.database.node.df # Node table m.basin.static.df # BasinStatc table m.write("test") ``` ### Some notes: - The config.py file cannot be autogenerated anymore. The schemas still can, but I disabled it for now to be sure (some imports error). ### Changes: I created new (parent) classes: - BaseModel, from Pydantic, with our own config - FileModel, like hydrolib-core (but now Pydantic v2), which can take a single filepath for initilization. Models who inherit require defining _load and _save, dealing with that filepath. - NodeModel, a class for nodes (where `add` will be). - TableModel, a class to read/write individual tables from/to gpkg/arrow. - SpatialTableModel, inherits TableModel, but reads/writes spatial stuff. I changed: - the Model class to be a carbon copy of Config (which has been deleted), so it mirrors the toml. - in turn this created a `database` NodeModel class (reflecting the field in the toml), with only Node and Edge underneath. - the NodeModel classes Basin from their node_type version to the one in Config, and set the type of the underlying table with a TypeVar like so: ```python class Terminal(NodeModel): static: TableModel[TerminalStaticSchema] ``` ### Yet to do: - [x] Update tests - [x] Fix sort! rules - [x] Delete node_types folder - [x] Link schemas to their Pydantic class (TableModel[TerminalStaticSchema] => TerminalStatic) --------- Co-authored-by: Martijn Visser <[email protected]> Co-authored-by: Hofer-Julian <[email protected]> Co-authored-by: Hofer-Julian <[email protected]>
visr
added a commit
that referenced
this issue
Nov 14, 2023
Fixes #512 Groundwork for #630 & #252 The code has become much simpler in some places (e.g. write_toml). ```python from ribasim import Model m = Model(filepath="generated_testmodels/basic/ribasim.toml") m.database.node.df # Node table m.basin.static.df # BasinStatc table m.write("test") ``` ### Some notes: - The config.py file cannot be autogenerated anymore. The schemas still can, but I disabled it for now to be sure (some imports error). ### Changes: I created new (parent) classes: - BaseModel, from Pydantic, with our own config - FileModel, like hydrolib-core (but now Pydantic v2), which can take a single filepath for initilization. Models who inherit require defining _load and _save, dealing with that filepath. - NodeModel, a class for nodes (where `add` will be). - TableModel, a class to read/write individual tables from/to gpkg/arrow. - SpatialTableModel, inherits TableModel, but reads/writes spatial stuff. I changed: - the Model class to be a carbon copy of Config (which has been deleted), so it mirrors the toml. - in turn this created a `database` NodeModel class (reflecting the field in the toml), with only Node and Edge underneath. - the NodeModel classes Basin from their node_type version to the one in Config, and set the type of the underlying table with a TypeVar like so: ```python class Terminal(NodeModel): static: TableModel[TerminalStaticSchema] ``` ### Yet to do: - [x] Update tests - [x] Fix sort! rules - [x] Delete node_types folder - [x] Link schemas to their Pydantic class (TableModel[TerminalStaticSchema] => TerminalStatic) --------- Co-authored-by: Martijn Visser <[email protected]> Co-authored-by: Hofer-Julian <[email protected]> Co-authored-by: Hofer-Julian <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's some technical debt in there, as it mixes all nodetypes and the required config options.
The text was updated successfully, but these errors were encountered: