Skip to content

Calin/imas integration#183

Draft
calin1989 wants to merge 54 commits intodevelopfrom
Calin/IMAS-integration
Draft

Calin/imas integration#183
calin1989 wants to merge 54 commits intodevelopfrom
Calin/IMAS-integration

Conversation

@calin1989
Copy link
Collaborator

Work in progress IMAS integration

logan-nc and others added 30 commits March 1, 2026 17:26
Exercise files for learning IMAS implementation:

NEW FILES (empty with TODO guides):
- src/DCON/WriteImas.jl: Empty function with detailed TODO steps
- test/runtests_imas.jl: Empty tests with TODO instructions

MODIFIED FILES (reverted to Point A + TODO markers):
- src/DCON/DCON.jl: Original code + 2 TODO markers showing where to add IMAS lines

REMAINING TO ADD TODO MARKERS:
- src/DCON/Main.jl (add dd parameter support)
- src/Equilibrium/Equilibrium.jl (add imas dispatch)
- src/Equilibrium/ReadEquilibrium.jl (add read_imas function)
- Project.toml (add dependencies)
- test/runtests.jl (register tests)

This allows manual practice of implementing IMAS integration.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Complete guide showing exactly where to add IMAS code in Main.jl.
Includes all 4 modification points with before/after code examples.

Next: Add TODO markers to remaining files (Equilibrium.jl, ReadEquilibrium.jl, Project.toml, runtests.jl)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added detailed guides for all remaining files:
- Main.jl (4 modification points)
- Equilibrium.jl (dispatch + signature)
- ReadEquilibrium.jl (read_imas function)
- Project.toml (dependencies)
- runtests.jl (include statement)

User can now manually implement all IMAS code following the guides!

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fix missing closing quote in DCON.jl include statement
- Ensure WriteImas.jl and runtests_imas.jl are properly formatted

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add magnetic axis Z position test for completeness
- Ensures all key equilibrium quantities are validated

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add standalone test demonstrating IMAS functionality
- Add comprehensive documentation for IMAS integration
- Fix Equilibrium.jl compilation error (AbstractExtrap import)

The standalone test verifies:
- IMAS data structures work correctly
- gEQDSK to IMAS conversion succeeds
- All IMAS source code is present and functional

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove AbstractExtrap/ExtendExtrap type annotations from ProfileSplines
- Use :extension symbol directly (matches actual usage in IMAS code)
- Remove unused imports from Equilibrium.jl

This fixes the "AbstractExtrap not defined" compilation error.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added missing package dependencies to enable JPEC compilation:
- AdaptiveArrayPools: Required for @with_pool macro in DirectEquilibrium.jl
- FastGaussQuadrature: Required by Vacuum module
- Roots: Required by ForceFreeStates module
- DelimitedFiles: Required by ForcingTerms module
- Statistics: Required by PerturbedEquilibrium module

Also added import for @with_pool macro in Equilibrium.jl.

These were pre-existing JPEC dependency issues, now resolved.
JPEC now compiles and loads successfully.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Added Splines module with Spl alias for module compatibility
- Added Util alias for Utilities module
- Integrated DCON module into main JPEC structure
- Fixed WriteImas.jl docstring interpolation issue
- Added missing imports to test file (Test, JPEC modules)

These changes enable full IMAS integration testing by properly
exposing the DCON module and its write_imas function through JPEC.

All modules now compile successfully.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Major fixes to enable IMAS integration testing:

**Import fixes in Equilibrium.jl:**
- Added Roots module and find_zero function
- Added FastInterpolations functions: n_series, PeriodicBC, ExtendExtrap, WrapExtrap
- Added AdaptiveArrayPools functions: checkpoint!, rewind!

**API fixes across multiple files:**
- Fixed all eq_config.control.* → eq_config.* references
- Fixed config.control.* → config.* references
- Fixed EquilibriumControl → EquilibriumConfig in tests

**DirectEquilibrium.jl fixes:**
- Changed ExtendExtrap() → :extension for cubic_interp calls

**Test file fixes (runtests_imas.jl):**
- Added missing imports: Test, JPEC, JPEC.Equilibrium, JPEC.DCON
- Fixed test API to match actual EquilibriumConfig structure
- Removed obsolete EquilibriumOutput references

These were pre-existing JPEC infrastructure issues uncovered
while testing IMAS integration. The IMAS integration code
itself is correct and functional (verified via standalone test).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
**Critical fixes:**
- Replaced all ExtendExtrap() → :extension throughout Equilibrium module
- Replaced all WrapExtrap() → :wrap throughout Equilibrium module
- Fixed SplinesMod module name (was incorrectly imported as Splines)
- Fixed comment syntax error in runtests_imas.jl (line 256)
- Removed unused ExtendExtrap/WrapExtrap imports from Equilibrium.jl

**Files modified:**
- src/Equilibrium/AnalyticEquilibrium.jl
- src/Equilibrium/DirectEquilibrium.jl
- src/Equilibrium/InverseEquilibrium.jl
- src/Equilibrium/Equilibrium.jl
- src/JPEC.jl (fixed SplinesMod import)
- test/runtests_imas.jl (fixed comment)

**TEST RESULTS:**
✅ IMAS equilibrium test: 6/6 PASSED (15.2s)
✅ IMAS write test: 21/21 PASSED (0.7s)
✅ Total: 27/27 tests PASSING

Full JPEC IMAS integration now functional!

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Created jpec_imas_full_workflow.jl - a complete end-to-end demonstration
of JPEC IMAS integration alongside the existing standalone test.

**What this demonstrates:**
1. Load equilibrium data from IMAS format into JPEC
2. Process equilibrium through JPEC pipeline
3. Run DCON stability analysis (synthetic for demo)
4. Write results back to IMAS mhd_linear structure
5. Verify complete workflow with 7 comprehensive checks

**Test Results:**
✅ All 7 verification checks PASS
✅ Equilibrium loads correctly via IMAS
✅ IMAS metadata properly set
✅ Mode structure correctly populated
✅ Stability results accurately stored

This complements imas_standalone_test.jl by showing the
full JPEC workflow integration, not just IMAS data structures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@logan-nc logan-nc mentioned this pull request Mar 6, 2026
Sophia Puscalau and others added 20 commits March 7, 2026 23:57
This test verifies that JPEC produces identical results whether reading
equilibrium from gEQDSK or IMAS format:

- Loads EQDSK_COCOS_02 via both gEQDSK and IMAS paths
- Compares equilibrium parameters (axis, flux, q-profile, grid)
- Runs DCON write_imas on both and compares outputs
- Verifies eigenvalues (et[1], etc.) are identical
- All 33 tests pass

This addresses the advisor's requirement to verify complete workflow
equivalence between gEQDSK and IMAS inputs.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Modified JPEC.main() signature to accept an optional dd parameter:
  - Old: main(args::Vector{String}=String[])
  - New: main(args::Vector{String}=String[], dd=nothing)

When dd is provided, it is passed to setup_equilibrium() for IMAS input.
This enables the workflow the advisor requested:
  - JPEC.main([path])      → uses gEQDSK/CHEASE/etc
  - JPEC.main([path], dd)  → uses IMAS dd structure

This completes the IMAS integration at the top level.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Replace ExtendExtrap() with :extension symbol
- Remove hint keyword arguments (no longer supported)
- Fix PeriodicBC usage for periodic data
- Make data explicitly periodic where needed

These changes address breaking API changes in newer FastInterpolations versions.
This commit resolves the issue where JPEC.main() produced different
eigenvalues when called with a gEQDSK file vs an IMAS dd object.

Three bugs fixed in src/Equilibrium/ReadEquilibrium.jl:

1. Incorrect q COCOS conversion (line 454):
   - Safety factor q is COCOS-independent
   - Removed incorrect multiplication by 2π
   - Now uses q directly from IMAS data

2. COCOS round-trip floating-point errors:
   - Added jpec_geqdsk_to_imas!() function to populate IMAS dd
     objects while preserving COCOS 2 convention
   - Avoids precision loss from COCOS 2→11→2 conversions
   - Added auto-detection in read_imas() to handle both COCOS 2
     and COCOS 11 input data
   - Preserves Chapter 1 IMAS workflow compatibility

3. psi_norm_grid construction precision (lines 493-495):
   - Changed from computed division to range() constructor
   - Ensures mathematically perfect grid points
   - Eliminates e-16 errors that amplified through numerical
     integration to factor-of-3 eigenvalue differences

Result: EFIT and IMAS paths now produce identical eigenvalues
        (-4.311e+01 -6.513e-01i) with identical integration
        steps (908), satisfying advisor's test requirement.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This test validates the advisor's requirement: gEQDSK ≡ IMAS

Test Design:
- PATH A: Load gEQDSK directly via EFIT
- PATH B: Convert gEQDSK to IMAS (COCOS 2), load via IMAS
- Run full JPEC/DCON calculation on both paths
- Compare eigenvalues from both paths

Results:
✅ ALL 34 eigenvalues match bit-for-bit (exact numerical equivalence)
✅ Advisor requirement SATISFIED
✅ IMAS integration is production-ready for COCOS 2

This proves that JPEC's IMAS integration produces identical
physics results to the traditional gEQDSK workflow.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changes:
1. Update FastInterpolations dependency to >=0.2.13 (from >=0.2.8)
   - Aligns with develop branch requirements
   - Ensures API compatibility

2. Fix jpec.toml path in test_final_diiid.jl
   - Now correctly reads from example directory using @__DIR__
   - Allows test to run from any working directory

Test Results:
✅ DIII-D test: ALL 34 eigenvalues match exactly (EFIT ≡ IMAS)
✅ Full workflow test: All 7 verification checks pass
✅ IMAS integration confirmed functional and production-ready

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ges, polish code

- Delete Chapter 1 OLD files (.bak files, old DCON-style demos, junk notebooks)
- Revert pre-existing files (docs, workflows, notebooks) to develop state
- Clean DCON references from IMAS implementation files (WriteImas.jl, ReadEquilibrium.jl, Equilibrium.jl)
- Fix indentation and remove extra blank lines in IMAS code
- Remove untracked artifacts (.ipynb_checkpoints, jpec binary, test_q_profiles_match.jl)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reverted docs, workflows, config files, and benchmarks to current
origin/develop state to reduce PR noise.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants