ENH: Convert pipelines to python scripts#1572
ENH: Convert pipelines to python scripts#1572imikejackson wants to merge 6 commits intoBlueQuartzSoftware:developfrom
Conversation
5c9f1a8 to
0713fd7
Compare
|
|
||
| for arg_name in sorted(args.keys()): | ||
| value = args[arg_name] | ||
| codec = self._registry.find(value) |
There was a problem hiding this comment.
We know the exact parameter since we have the filter so we should just use a mapping of filter parameter to python conversion.
| MODULE_IMPORTS: dict[str, str] = { | ||
| "simplnx": "import simplnx as nx", | ||
| "orientationanalysis": "import orientationanalysis as nxor", | ||
| "itkimageprocessing": "import itkimageprocessing as nxitk", | ||
| } |
There was a problem hiding this comment.
This seems redundant given that an import statement can be constructed from the above MODULE_ALIASES.
|
|
||
| def _encode_simple_value(value: Any) -> str: | ||
| """Encode a single simple value to a Python expression string.""" | ||
| import pathlib |
There was a problem hiding this comment.
This should be with the other imports.
| print(generator.generate(pipeline)) | ||
| """ | ||
|
|
||
| from __future__ import annotations |
There was a problem hiding this comment.
I believe this is only for deferred evaluation of annotations but those don't seem to be used? Also we should be importing the simplnx modules. And some type annotations can be updated from Any.
| return registry | ||
|
|
||
|
|
||
| def create_default_generator() -> PipelineCodeGenerator: |
There was a problem hiding this comment.
The PipelineCodeGenerator doesn't change so I think it would be easier if you could call this from a function something like generate_python_pipeline() using a constant version of the generator.
| "import shutil", | ||
| "from pathlib import Path", | ||
| "", | ||
| "def check_filter_result(filter: nx.IFilter, result: nx.IFilter.ExecuteResult) -> None:", |
There was a problem hiding this comment.
We talked about moving this function into the bindings module directly. Not difficult just wasn't a priority before.
| filters = [pipeline[i] for i in range(len(pipeline))] | ||
| return self._generate_full(filters) | ||
|
|
||
| def generate_filters(self, filters: list[Any]) -> str: |
There was a problem hiding this comment.
These functions specifically want a PipelineFilter object but I think it should support instances of IFilter which the pipeline filter can just hand to that function. I think it would be to have a function to generate a single filter as well.
wrapping/python/CMakeLists.txt
Outdated
| file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/utils/simplnx_utilities.py | ||
| DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/." | ||
| ) |
There was a problem hiding this comment.
This won't copy to the correct place on the Visual Studio generator.
| install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/utils/simplnx_utilities.py | ||
| DESTINATION ${SIMPLNX_PY_INSTALL_DIR} | ||
| ) |
There was a problem hiding this comment.
Should make sure this is good for conda builds.
|
|
||
| pipeline = nx.Pipeline.from_file("path/to/pipeline.d3dpipeline") | ||
| generator = create_default_generator() | ||
| print(generator.generate(pipeline)) |
There was a problem hiding this comment.
We should a test to ensure that we generate valid code ideally. Minimum is that the script runs.
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
0713fd7 to
2d13c62
Compare
Exposes a Python method that returns a dict mapping argument names to their parameter type UUID strings. This enables UUID-based codec lookup in simplnx_utilities.py instead of duck-typing values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Flatten PipelineCodeGenerator/CodecRegistry/FilterModuleResolver classes into module-level functions (generate_python_pipeline, generate_python_filters) - Use UUID-based parameter-to-codec mapping instead of duck-typing values - Import simplnx at module top level; use concrete types where possible - Remove redundant MODULE_IMPORTS dict (construct from MODULE_ALIASES) - Remove unused os/shutil/Path imports from generated code - Move importlib import to module top level - Remove from __future__ import annotations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use $<TARGET_FILE_DIR:simplnx> instead of CMAKE_RUNTIME_OUTPUT_DIRECTORY so the copy works correctly with Visual Studio and other multi-config generators that append a config subdirectory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests that generate_python_pipeline() and generate_python_filters() produce syntactically valid Python code. Covers basic filters and complex parameter types like ArrayThresholdSet. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename 'result' to 'uuidDict' to avoid shadowing the outer 'result' variable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This lays down infrastructure that allows users to convert a .d3dpipeline file into a fully functioning python script.