forked from Loop3D/LoopStructural
-
Notifications
You must be signed in to change notification settings - Fork 1
Implement comprehensive JSON serialization and deserialization for geological models #4
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
Draft
Copilot
wants to merge
7
commits into
master
Choose a base branch
from
copilot/improve-json-serialization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve JSON serialization for geological model
Implement comprehensive JSON serialization for geological models
Oct 14, 2025
Copilot finished work on behalf of
lachlangrose
October 14, 2025 06:45
Owner
|
@copilot can you start implementing from_dict functionality for all model elements |
- Add from_dict methods to GeologicalInterpolator with automatic type dispatch - Implement from_dict for DiscreteInterpolator to reconstruct support and solution - Add from_dict to GeologicalFeature to reconstruct features with interpolators - Implement from_dict for GeologicalModel to fully reconstruct models - Add to_dict and rotation_xy parameter to TetMesh for proper serialization - Update load_from_json to use from_dict instead of raising NotImplementedError - Add 4 new tests for deserialization (from_dict, load_from_json, FDI support) - Update example to demonstrate full round-trip serialization/deserialization Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Author
I've implemented full Core changes:
Usage: # Dictionary round-trip
model_dict = model.to_dict()
model2 = GeologicalModel.from_dict(model_dict)
# File round-trip
model.save_to_json('model.json')
model2 = GeologicalModel.load_from_json('model.json')Testing:
See commit for full implementation details. |
The BaseStructuredSupport stores nsteps internally as nsteps+1 (added in __init__). When serializing, we need to subtract 1 so that when deserialized and incremented again, we get the correct value. This ensures support structures maintain the correct dimensions after round-trip serialization. Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Copilot
AI
changed the title
Implement comprehensive JSON serialization for geological models
Implement comprehensive JSON serialization and deserialization for geological models
Oct 14, 2025
Copilot finished work on behalf of
lachlangrose
October 14, 2025 23:21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements comprehensive JSON serialization and deserialization support for geological models in LoopStructural, enabling the entire model state—including interpolators and their solutions—to be saved to and loaded from JSON format.
Problem
Previously, the
to_dict()method existed but had several limitations:from_dict(),load_from_json()) were not implementedSolution
Enhanced the serialization system across all model components to ensure complete, JSON-compatible serialization and implemented full deserialization capability:
Core Changes
Interpolators
GeologicalInterpolator.to_dict(): Converts numpy arrays to lists for JSON compatibilityGeologicalInterpolator.from_dict(): Reconstructs interpolators with automatic type dispatchDiscreteInterpolator.to_dict(): Includes solution coefficients (carray) and support structureDiscreteInterpolator.from_dict(): Reconstructs support, solution coefficients, and constraint dataSupport Structures
BaseStructuredSupport.to_dict(): Converts all numpy arrays (origin, nsteps, step_vector, rotation_xy) to listsTetMesh.to_dict(): Added to include type information for proper deserializationTetMesh.__init__(): Updated to accept rotation_xy parameterStructuredGrid.to_dict(): Uses proper type name serializationFeatures
BaseFeature.to_dict(): Properly serializes FeatureType enumsGeologicalFeature.to_dict(): Includes complete interpolator state viato_dict()GeologicalFeature.from_dict(): Reconstructs features with their interpolatorsModel
GeologicalModel.to_dict(): Serializes all features with their complete stateGeologicalModel.from_dict(): Fully reconstructs models from dictionariesGeologicalModel.save_to_json(): Convenience method for saving to fileGeologicalModel.load_from_json(): Loads and reconstructs models from JSON filesWhat's Serialized
The complete model now includes:
Usage
Testing
tests/unit/modelling/test_model_serialization.pyDocumentation
examples/1_basic/plot_8_model_serialization.pySERIALIZATION_IMPROVEMENTS.mdWhat Works Now
Complete round-trip serialization and deserialization:
Backward Compatibility
All changes are backward compatible:
to_json()methods continue to workOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.