-
Notifications
You must be signed in to change notification settings - Fork 44
Add json import/export to SimulationData #85
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
Conversation
nlohmann/json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds JSON import/export functionality to SimulationData, enabling serialization and deserialization of simulation configurations. The implementation includes comprehensive unit tests covering round-trip conversion, precision handling, edge cases, and error scenarios.
Key Changes:
- Added JSON serialization/deserialization support for all simulation data structures (elements, surfaces, apertures, optical properties, ray sources)
- Implemented
import_json_file()andexport_json_file()methods on SimulationData - Created extensive test suite with 8 test cases covering various scenarios including round-trip conversion, large field comparison, precision validation, empty cases, and error handling
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 33 comments.
Show a summary per file
| File | Description |
|---|---|
| google-tests/unit-tests/simulation_runner/native_runner/calculator_factory_test.cpp | Added write_json override to UnknownSurface test fixture |
| google-tests/unit-tests/simulation_data/file_io_test.cpp | New test file with comprehensive JSON I/O tests including round-trip, precision, validation, and error handling |
| google-tests/unit-tests/simulation_data/aperture_test.cpp | Added write_json implementation to TestAperture fixture |
| google-tests/unit-tests/simulation_data/CMakeLists.txt | Updated build configuration to include new test file and required dependencies |
| coretrace/simulation_data/surface.hpp | Added write_json virtual method and JSON constructors to all surface types; added SurfaceTypeMap |
| coretrace/simulation_data/surface.cpp | Implemented JSON serialization/deserialization for Cone, Cylinder, Flat, Parabola, and Sphere surfaces |
| coretrace/simulation_data/stage_element.hpp | Added JSON constructor and write_json method declarations |
| coretrace/simulation_data/stage_element.cpp | Implemented JSON import/export for stage elements with validation |
| coretrace/simulation_data/single_element.hpp | Added JSON constructor and write_json method declarations |
| coretrace/simulation_data/single_element.cpp | Implemented JSON serialization for single elements including aperture, surface, and optical properties |
| coretrace/simulation_data/simulation_data.hpp | Added public API methods for JSON import/export and ray source iteration |
| coretrace/simulation_data/simulation_data.cpp | Delegated JSON I/O methods to simdata_io functions |
| coretrace/simulation_data/simdata_io.hpp | Added write_json_file, load_json_file functions and get_enum_from_string template utility |
| coretrace/simulation_data/simdata_io.cpp | Core JSON serialization logic for entire simulation including parameters, sources, and elements |
| coretrace/simulation_data/ray_source.hpp | Added UNKNOWN enum value and SunShapeMap for string conversion |
| coretrace/simulation_data/optical_properties.hpp | Added JSON constructor and write_json method; added InteractionTypeMap |
| coretrace/simulation_data/optical_properties.cpp | Implemented JSON serialization for optical properties |
| coretrace/simulation_data/json_helpers.hpp | New utility header for JSON value extraction with NaN handling |
| coretrace/simulation_data/error_distributions.hpp | Added UNKNOWN enum value and DistributionTypeMap |
| coretrace/simulation_data/element.hpp | Added pure virtual write_json methods and is_top_level check to Element interface |
| coretrace/simulation_data/element.cpp | Implemented JSON constructor and common JSON serialization for ElementBase |
| coretrace/simulation_data/composite_element.hpp | Added JSON constructor and write_json method declarations |
| coretrace/simulation_data/composite_element.cpp | Implemented recursive JSON serialization for composite elements |
| coretrace/simulation_data/aperture.hpp | Added write_json virtual method and JSON constructors for all aperture types; added ApertureTypeMap |
| coretrace/simulation_data/aperture.cpp | Implemented JSON serialization/deserialization for all aperture types |
| coretrace/simulation_data/CMakeLists.txt | Added nlohmann_json library dependency via FetchContent |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
google-tests/unit-tests/simulation_runner/native_runner/calculator_factory_test.cpp
Outdated
Show resolved
Hide resolved
…ator_factory_test.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to simdata_io_json
0f8ee57 to
c80c11d
Compare
jmaack24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! Looks really good to me. I left a few notes on things.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to simdata_io_json
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to simdata_io_json
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to simdata_io_json
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to simdata_io_json
Added ability to import/export simulation data to json.
Added unit tests, and end to end testing of json functionality.