Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/typing-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# working-directory: ./${{ matrix.package-name }}
run: |
python -m pip install --upgrade pip
python -m pip install mypy ruff types-PyYAML
python -m pip install mypy ruff types-PyYAML types-requests

- name: Typing check with mypy
# working-directory: ./${{ matrix.package-name }}
Expand Down
2 changes: 1 addition & 1 deletion geos-trame/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = [
"trame-components==2.4.2",
"trame-gantt==0.1.5",
"mpld3<0.5.11",
"xsdata==24.5",
"xsdata[cli]>=25.4",
"xsdata-pydantic[lxml]==24.5",
"pyvista==0.45.2",
"dpath==2.2.0",
Expand Down
6 changes: 3 additions & 3 deletions geos-trame/src/geos/trame/app/deck/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from geos.trame.app.geosTrameException import GeosTrameException
from geos.trame.app.io.xml_parser import XMLParser
from geos.trame.app.utils.file_utils import normalize_path
from geos.trame.schema_generated.schema_mod import Problem
from geos.trame.schema_generated.schema_mod import ProblemType


class DeckFile( object ):
Expand All @@ -30,7 +30,7 @@ def __init__( self, filename: str, **kwargs: Any ) -> None:

self.inspect_tree: dict[ Any, Any ] | None = None
self.pb_dict: dict[ str, Any ] | None = None
self.problem: Problem | None = None
self.problem: ProblemType | None = None
self.xml_parser: XMLParser | None = None
self.root_node = None
self.filename = normalize_path( filename )
Expand Down Expand Up @@ -79,7 +79,7 @@ def open_deck_file( self, filename: str ) -> None:
)
parser = XmlParser( context=context, config=ParserConfig() )
try:
self.problem = parser.parse( simulation_deck, Problem )
self.problem = parser.parse( simulation_deck, ProblemType )
except ElementTree.XMLSyntaxError as e:
msg = "Failed to parse input file %s:\n%s\n" % ( filename, e )
raise GeosTrameException( msg ) from e
Expand Down
14 changes: 7 additions & 7 deletions geos-trame/src/geos/trame/app/deck/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from geos.trame.app.deck.file import DeckFile
from geos.trame.app.geosTrameException import GeosTrameException
from geos.trame.schema_generated.schema_mod import Problem, Included, File, Functions
from geos.trame.schema_generated.schema_mod import ProblemType, Included, File, Functions
from geos.trame.app.utils.file_utils import normalize_path, format_xml


Expand Down Expand Up @@ -100,14 +100,14 @@ def decode( self, path: str ) -> BaseModel | None:
return decoder.decode( data[ 0 ] )

@staticmethod
def decode_data( data: dict ) -> Problem:
def decode_data( data: dict ) -> ProblemType:
"""Convert a data to a xml serializable file."""
context = XmlContext(
element_name_generator=text.pascal_case,
attribute_name_generator=text.camel_case,
)
decoder = DictDecoder( context=context, config=ParserConfig() )
node: Problem = decoder.decode( data )
node: ProblemType = decoder.decode( data )
return node

@staticmethod
Expand Down Expand Up @@ -157,8 +157,8 @@ def write_files( self ) -> None:
files = self._split( pb )

for filepath, content in files.items():
model_loaded: Problem = DeckTree.decode_data( content )
model_with_changes: Problem = self._apply_changed_properties( model_loaded )
model_loaded: ProblemType = DeckTree.decode_data( content )
model_with_changes: ProblemType = self._apply_changed_properties( model_loaded )

assert ( self.input_file is not None and self.input_file.xml_parser is not None )
if self.input_file.xml_parser.contains_include_files():
Expand All @@ -178,7 +178,7 @@ def write_files( self ) -> None:
self._ctrl.on_add_success( title="File saved", message=f"File {basename} has been saved." )

@staticmethod
def _append_include_file( model: Problem, included_file_path: str ) -> None:
def _append_include_file( model: ProblemType, included_file_path: str ) -> None:
"""Append an Included object which follows this structure according to the documentation.

<Included>
Expand Down Expand Up @@ -235,7 +235,7 @@ def _convert_to_snake_case( content: str ) -> str:
"""
return "".join( [ "_" + char.lower() if char.isupper() else char for char in content ] ).lstrip( "_" )

def _apply_changed_properties( self, model: Problem ) -> Problem:
def _apply_changed_properties( self, model: ProblemType ) -> ProblemType:
"""Retrieves all edited 'properties' from the simput_manager and apply it to a given model."""
manager = get_simput_manager( self._sm_id )
modified_proxy_ids: set[ str ] = manager.proxymanager.dirty_proxy_data
Expand Down
4 changes: 2 additions & 2 deletions geos-trame/src/geos/trame/app/io/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _update_vtkwell( self, well: Vtkwell, path: str, show: bool ) -> None:
self.well_viewer.add_mesh( well_polydata, path )

def _update_internalwell( self, well: InternalWell, path: str, show: bool ) -> None:
"""Used to control the visibility of the InternalWell.
"""Used to control the visibility of the InternalWellType.

This method will create the mesh if it doesn't exist.
"""
Expand All @@ -134,7 +134,7 @@ def _update_internalwell( self, well: InternalWell, path: str, show: bool ) -> N

@staticmethod
def __parse_polyline_property( polyline_property: str, dtype: Type[ Any ] ) -> np.ndarray:
"""Internal method used to parse and convert a property, such as polyline_node_coords, from an InternalWell.
"""Internal method used to parse and convert a property, such as polyline_node_coords, from an InternalWellType.

This string always follow this for :
"{ { 800, 1450, 395.646 }, { 800, 1450, -554.354 } }"
Expand Down
4 changes: 2 additions & 2 deletions geos-trame/src/geos/trame/app/ui/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from geos.trame.app.data_types.tree_node import TreeNode
from geos.trame.app.deck.tree import DeckTree
from geos.trame.app.utils.dict_utils import iterate_nested_dict
from geos.trame.schema_generated.schema_mod import Problem
from geos.trame.schema_generated.schema_mod import ProblemType

vuetify.enable_lab()

Expand Down Expand Up @@ -113,7 +113,7 @@ def source( self ) -> dict | None:
# TODO
# v should be a proxy like the one in paraview simple
# maybe it can be Any of schema_mod (e.g. Problem)
def _set_source( self, v: Problem | None ) -> None:
def _set_source( self, v: ProblemType | None ) -> None:

# TODO replace this snippet
from xsdata.formats.dataclass.serializers.config import SerializerConfig
Expand Down
20 changes: 11 additions & 9 deletions geos-trame/src/geos/trame/app/ui/viewer/boxViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def __init__( self, mesh: pv.UnstructuredGrid, box: Box ) -> None:
self._mesh: pv.UnstructuredGrid = mesh

self._box: Box = box
self._box_polydata: pv.PolyData = None
self._box_polydata_actor: pv.Actor = None
self._box_polydata: pv.PolyData | None = None
self._box_polydata_actor: pv.Actor | None = None

self._extracted_cells: pv.UnstructuredGrid = None
self._extracted_cells_actor: pv.Actor = None
self._extracted_cells: pv.UnstructuredGrid | None = None
self._extracted_cells_actor: pv.Actor | None = None

self._compute_box_as_polydata()
self._compute_intersected_cell()
Expand All @@ -32,7 +32,7 @@ def get_box_polydata( self ) -> pv.PolyData | None:
"""Get the box polydata."""
return self._box_polydata

def get_box_polydata_actor( self ) -> pv.Actor:
def get_box_polydata_actor( self ) -> pv.Actor | None:
"""Get the actor generated by a pv.Plotter for the box polydata."""
return self._box_polydata_actor

Expand Down Expand Up @@ -86,16 +86,18 @@ def _retrieve_bounding_box( self ) -> list[ float ]:

def _compute_intersected_cell( self ) -> None:
"""Extract the cells from the mesh that are inside the box."""
ids = self._mesh.find_cells_within_bounds( self._box_polydata.bounds )
if self._box_polydata:
ids = self._mesh.find_cells_within_bounds( self._box_polydata.bounds )

saved_ids: list[ int ] = []

for id in ids:
cell: pv.vtkCell = self._mesh.GetCell( id )

is_inside = self._check_cell_inside_box( cell, self._box_polydata.bounds )
if is_inside:
saved_ids.append( id )
if self._box_polydata:
is_inside = self._check_cell_inside_box( cell, self._box_polydata.bounds )
if is_inside:
saved_ids.append( id )

if len( saved_ids ) > 0:
self._extracted_cells = self._mesh.extract_cells( saved_ids )
Expand Down
11 changes: 6 additions & 5 deletions geos-trame/src/geos/trame/app/ui/viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def __init__(
self._cell_data_array_names: list[ str ] = []
self._source = source
self._pl = pv.Plotter()
self._pl.iren.initialize()
if self._pl.iren:
self._pl.iren.initialize()
self._mesh_actor: vtkActor | None = None

self.CUT_PLANE = "on_cut_plane_visibility_change"
Expand Down Expand Up @@ -126,7 +127,7 @@ def rendering_menu_extra_items( self ) -> None:
def update_viewer( self, active_block: BaseModel, path: str, show_obj: bool ) -> None:
"""Add from path the dataset given by the user.

Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation, Box.
Supported data type is: VtkwellType, VtkmeshType, InternalWellType, PerforationType, BoxType.

object_state : array used to store path to the data and if we want to show it or not.
"""
Expand Down Expand Up @@ -220,7 +221,7 @@ def _get_perforation_size( self ) -> float | None:
return None

def _update_internalwell( self, path: str, show: bool ) -> None:
"""Used to control the visibility of the InternalWell.
"""Used to control the visibility of the InternalWellType.

This method will create the mesh if it doesn't exist.
"""
Expand All @@ -235,7 +236,7 @@ def _update_internalwell( self, path: str, show: bool ) -> None:
self.ctrl.view_update()

def _update_vtkwell( self, path: str, show: bool ) -> None:
"""Used to control the visibility of the Vtkwell.
"""Used to control the visibility of the VtkwellType.

This method will create the mesh if it doesn't exist.
"""
Expand Down Expand Up @@ -273,7 +274,7 @@ def _update_actor_array( self, **_: Any ) -> None:
self.ctrl.view_update()

def _update_vtkmesh( self, show: bool ) -> None:
"""Used to control the visibility of the Vtkmesh.
"""Used to control the visibility of the VtkmeshType.

This method will create the mesh if it doesn't exist.

Expand Down
67 changes: 38 additions & 29 deletions geos-trame/src/geos/trame/schema_generated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,58 @@ to parse, serialize and deserialize these files in trame with `trame-simput`, we
generate a serializable class for each balise described in the schema used by GEOS.

For that we use a python module named `xsd-pydantic` which allows us to generate a file.
It will contain all class for a given xsd schema file.
It will contain all class for a given xsd schema file.

When starting the trame application, we can instantiate the expected dataclass when parsing
the input file.

## How to generate a new file

#### 1. Clone the GEOS Repository
#### 1. Get GEOS validation schema file
First, retrieve the `schema.xsd` corresponding to the GEOS version you want to use.

```bash
git clone [email protected]:GEOS-DEV/GEOS.git
```
> [!WARNING]
> We advise to use GEOS version from commit [#1e617be](https://github.com/GEOS-DEV/GEOS/commit/1e617be8614817d92f0a7a159994cbed1661ff98). You may encounter compatibility issues with older versions.

#### 2. Create a dedicate venv
In a sourced virtual environement set for geos_trame,

```bash
cd <path-to-geos-trame>
python -m venv pydantic-venv
source pydantic-venv/bin/activate
pip install -e .
pip install "xsdata[cli]"
cd src/geos_trame/schema_generated
(venv) cd geosPythonPackages/geos-trame/src/geos/trame/schema_generated
(venv) python generate_schema.py -g
(venv) mv schema_<GEOS-commit-sha>.xsd schema.xsd
(venv) python generate_schema.py -v <GEOS-commit-sha>
```

#### 3. Generate the new file

The full documentation is [here](https://xsdata-pydantic.readthedocs.io/en/latest/codegen/).
This two stage approach is defaulted:

```bash
xsdata <path-to-GEOS>/src/coreComponents/schema/schema.xsd --output pydantic --package generated_models --structure-style single-package --include-header
```
1. to take the latest commit on GEOS' `develop`. However, if a particular commit on `develop` is of interest,
you can pass it through the option `-c <GEOS-commit-sha>`. It will generate `schema_<GEOS-commit-sha>.xsd`.
2. to generate the `schema_mod.py` packages, metadata-ing the commit number in the header.

Then update the generated file, at the beginning, by adding the geos commit used:
In any other case, `schema.xsd` can be found in [GEOS Github repository](https://github.com/GEOS-DEV/GEOS) under `GEOS/src/coreComponents/schema/schema.xsd`
and the first step can be skipped.

For example:
The second stage relies on `xsdata[cli]` interfaced with `pydantic` as driver.
The full documentation can be found [here](https://xsdata-pydantic.readthedocs.io/en/latest/codegen/).

```py
"""This file was generated by xsdata, v24.6.1, on 2024-11-29

Generator: PydanticGenerator
See: https://xsdata.readthedocs.io/

GEOS commit hash: <add-the-commit-hash-here>
"""
```
Options to the helper script can be displayed with `--help` parameters:

```bash
$ python generate_schema.py --help

Generate schema from schema.xsd file

optional arguments:
-h, --help show this help message and exit
-g, --get-schema Get the latest schema files.
-c COMMIT, --commit COMMIT
Force a specific GEOS develop's commit for schema
download
-s SCHEMAFILE, --schemaFile SCHEMAFILE
Filepath to GEOS schema file.
-cf CONFIGFILE, --configFile CONFIGFILE
Filepath to xml configuration file for schema
generation.
-v VERSION, --version VERSION
GEOS commit sha or version identification.
```
16 changes: 16 additions & 0 deletions geos-trame/src/geos/trame/schema_generated/config_schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>


<Config xmlns="http://pypi.org/project/xsdata" version="25.4">
<Output maxLineLength="79">
<Package>schema_mod</Package>
<Format repr="true" eq="true" order="false" unsafeHash="false" frozen="false" slots="false" kwOnly="false">pydantic</Format>
<Structure>single-package</Structure>
<IncludeHeader>false</IncludeHeader>
<DocstringStyle>reStructuredText</DocstringStyle>
<RelativeImports>false</RelativeImports>
</Output>
<Substitutions>
<Substitution type="class" search="(?&lt;!Problem)Type$" replace=""/>
</Substitutions>
</Config>
Loading