Skip to content

Add Pellet I/O and comparison utilities#12

Open
mgyoo86 wants to merge 5 commits into
perf/simple_tracefrom
feat/pellet_io
Open

Add Pellet I/O and comparison utilities#12
mgyoo86 wants to merge 5 commits into
perf/simple_tracefrom
feat/pellet_io

Conversation

@mgyoo86

@mgyoo86 mgyoo86 commented Oct 27, 2025

Copy link
Copy Markdown
Member

Prerequiste

Dependencies: This PR builds on top of perf/simple_trace branch


Summary

Adds HDF5 serialization support and comprehensive equality operators for the Pellet type. Refactors type system for better maintainability.

Changes

Type System Refactoring

  • Simplify Pellet from 7 type parameters to 1 (FT<:AbstractFloat)
  • Extract type definitions to new src/types.jl module

HDF5 I/O Support for Pellet struct

  • pellet2hdf(pellet, filename) - serialize Pellet to HDF5
  • hdf2pellet(filename) - deserialize from HDF5 to Pellet

Equality Operators

  • Base.isequal
  • Base.:(==)
  • Base.isapprox
  • Base.diff

New Dependencies

  • HDF5.jl - for file I/O
  • StaticArrays.jl - for velocity_vector field

Usage Example

import PAM

# Run simulation
pellet = PAM.run_PAM(dd; t_start=0.0, t_finish=0.1, time_step=0.01, ...)

# Save to file
PAM.pellet2hdf(pellet, "pellet_output.h5")

# Load from file
loaded = PAM.hdf2pellet("pellet_output.h5")

# Compare results
loaded == pellet          # Exact equality
loaded  pellet           # Approximate equality
diff(loaded, pellet)      # Show differences

Test Coverage

  • All new functionality is tested ✅

- Extract type definitions to new src/types.jl file
- Reduce Pellet struct from 7 type parameters to single FT parameter
- Use explicit concrete types (Bool, Symbol, Vector{FT}) instead of over-parameterization
- Improves code organization and type clarity
- Create src/io.jl with pellet2hdf and hdf2pellet functions
- Add HDF5 dependency (v0.17.2) to Project.toml
- Implement automatic type conversion (Symbol ↔ String, MVector handling)
- Support selective field serialization (exclude private fields)
- Add comprehensive docstrings for I/O functions
- Implement Base.isequal: programming equality (NaN == NaN, missing == missing)
- Implement Base.:(==): mathematical equality (NaN ≠ NaN, missing propagation)
- Implement Base.isapprox: approximate equality with tolerance (rtol/atol)
- Add diff() utility function for verbose field comparison
- Define public_fields constant to optimize field iteration
- Move comparison logic from io.jl to types.jl (better code organization)
- Update I/O functions to use public_fields constant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant