Skip to content

Conversation

@theo-brown
Copy link
Collaborator

@theo-brown theo-brown commented Aug 5, 2025

This enables loading an equilibrium from any timeslice in an equilibrium IDS. Useful if resuming from pre-existing simulations.

  • Implementation
  • Testing

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 2422ada to 6632990 Compare August 5, 2025 12:09
@theo-brown
Copy link
Collaborator Author

@MateoBell what's the provenance of the ITERhybrid_COCOS17_IDS_ddv4.nc file? I'd like to extend it to have multiple time slices so that I can test what I've implemented in this PR.

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch 2 times, most recently from e939fb9 to 678f7cd Compare August 6, 2025 09:56
@theo-brown
Copy link
Collaborator Author

Linked to #1391. During investigating the different geometry loaders in ST, I am comparing eqdsk from various timesteps with CHEASE, IMAS, etc. Hence, I need to be able to load different slices from the IMAS equilibrium IDS.

@MateoBell
Copy link
Collaborator

@MateoBell what's the provenance of the ITERhybrid_COCOS17_IDS_ddv4.nc file? I'd like to extend it to have multiple time slices so that I can test what I've implemented in this PR.

The .nc file was generated with chease converting the EQDSK_ITERhybrid_COCOS02.eqdsk (actually not completely sure which eqdsk of the examples, but it is the one which was used to compare to the CHEASE default geometry file). There is a script to run CHEASE from an eqdsk and save it to an IDS in a database, and then I converted it in netCDF. The script probably requires IMAS core so I can try to generate an IDS with multiple time slices with given eqdsk if needed.

@theo-brown
Copy link
Collaborator Author

theo-brown commented Aug 8, 2025

Thanks! I think for this PR we ideally would have an IDS with different profiles across the time steps we're comparing. This will also pave the way for smoothly interpolating between geometries to have evolving geometry over the run, but this may require rerunning CHEASE (or equivalent fixed-boundary solver) to produce something consistent.

We could, for example, run CHEASE twice using the pprime and FFprime profiles from the beginning and end of the TORAX iterhybrid rampup case as inputs, to give two different geometries for the start and end of the ramp.

What do you think?

@MateoBell
Copy link
Collaborator

MateoBell commented Aug 11, 2025

We could, for example, run CHEASE twice using the pprime and FFprime profiles from the beginning and end of the TORAX iterhybrid rampup case as inputs, to give two different geometries for the start and end of the ramp.

Yes fully agree ! I think it is a good idea so we can get different geometries at different times to compare.

@theo-brown
Copy link
Collaborator Author

theo-brown commented Aug 11, 2025

I've never run CHEASE before, if you're able would you be able to generate the two geometries?

Failing CI is just the placeholder test that's waiting for the new data.

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 678f7cd to 40fd9cd Compare August 12, 2025 13:51
@MateoBell
Copy link
Collaborator

Ok I think I should be able to do it, will try to do it asap !

@jcitrin
Copy link
Collaborator

jcitrin commented Aug 14, 2025

Thanks both! Having a multiple time-slice IDS loader and a test for it would be ideal

@MateoBell
Copy link
Collaborator

I added the multiple time slices IDS, but I just noticed the netCDF file is pretty heavy. I generated it with CHEASE for all time slices of the output simulation from iterhybrid_rampup config. If needed I can reduce the number of time slices to reduce the weight.
Also I modified a bit the tests to make sure the IDS was generated properly and passing it, I fixed it rapidly so you might want to do it more properly.

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 4b4b771 to 6c9e5bd Compare August 19, 2025 09:44
@theo-brown
Copy link
Collaborator Author

theo-brown commented Aug 19, 2025

Incredible, thanks so much @MateoBell. Your fixes to the tests also seem fine!

In the latest force push I just rebased onto main.

For reference, the full .nc is 56.21 MB (GitHub's recommended limit is 50MB). I think we can definitely reduce the number of timeslices - maybe we should go down to ~10 from ~40?

@jcitrin
Copy link
Collaborator

jcitrin commented Aug 19, 2025

Thanks both!

~10 from ~40?

Yes, good idea to not load up the repo with large files

@MateoBell
Copy link
Collaborator

Okay just replaced it with 11 time slices evenly spaced in time, the file is now ~16MB !

@theo-brown theo-brown requested a review from jcitrin August 19, 2025 12:18
@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 4234aa1 to 95a7fde Compare August 21, 2025 20:49
@theo-brown theo-brown requested a review from jcitrin August 21, 2025 21:03
@theo-brown theo-brown requested a review from Nush395 September 1, 2025 08:12
Copy link
Collaborator

@Nush395 Nush395 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Theo! Left a few comments

if slice_time is not None:
# Find the closest time in the IDS that is <= slice_time
slice_index = (
np.searchsorted(equilibrium.time, slice_time, side="right") - 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is equilibrium.time guaranteed to be sorted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure. Happy to add a check and then sort if it's not.

@jcitrin
Copy link
Collaborator

jcitrin commented Sep 10, 2025

@theo-brown , sorry this one slipped through the cracks.

If it's still relevant can you respond to any comments, sync, and we'll re-review?

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 95a7fde to 3cccd78 Compare September 10, 2025 12:19
@theo-brown
Copy link
Collaborator Author

No problem, it also slipped off my radar! I didn't see @Nush395 had reviewed it. Changes made! I wasn't sure whether it's ok to assume time is sorted in the equilibrium IDS, I'm not sure whether this is enforced. Can easily add a check and do a sort-then-search if you think it's required.

@theo-brown theo-brown requested a review from Nush395 September 11, 2025 12:53
Copy link
Collaborator

@Nush395 Nush395 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Theo! Looks great

@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 3cccd78 to e32aa42 Compare September 11, 2025 18:34
@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from e32aa42 to 51b30bf Compare September 11, 2025 18:35
Added an IDS with multiple time slices for testing
@theo-brown theo-brown force-pushed the imas-geometry-timeslice branch from 51b30bf to 5d2093b Compare September 11, 2025 18:38
@theo-brown
Copy link
Collaborator Author

Thanks for the review @Nush395!

Changes:

  • Squashed commits
  • Added check if time is sorted, and sort if not
  • Removed "(default 0)"
  • Fixed typo in README
  • Switched to assertRaisesRegex to check the error properly

@Nush395 Nush395 added the copybara:import-manual Set when ready for copybara manual import label Sep 11, 2025
f"{len(equilibrium.time_slice)} time slices"
)
IMAS_data = equilibrium.time_slice[slice_index]
B_0 = np.abs(IMAS_data.global_quantities.magnetic_axis.b_field_phi)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this additional unused B_0, should this be removed? If so I can do so.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is definitely wrong, not sure why I added it 🤔 please remove!

@copybara-service copybara-service bot merged commit 2e5f70e into main Sep 12, 2025
19 checks passed
@theo-brown theo-brown deleted the imas-geometry-timeslice branch September 12, 2025 10:13
@theo-brown theo-brown restored the imas-geometry-timeslice branch September 12, 2025 10:14
@theo-brown
Copy link
Collaborator Author

@Nush395 I think something might've gone wrong in the copybara import.

From the merge commit: 2e5f70e

slice_time: float | None = None

From the branch: 5d2093b

slice_time: pydantic.NonNegativeFloat | None = None

@Nush395
Copy link
Collaborator

Nush395 commented Sep 12, 2025

@Nush395 I think something might've gone wrong in the copybara import.

From the merge commit: 2e5f70e

slice_time: float | None = None

From the branch: 5d2093b

slice_time: pydantic.NonNegativeFloat | None = None

@jcitrin commented in internal review that this slice_time could be negative so I modified this before submitting. Will call out any changes more explicitly in future!

jcitrin: "time can be negative, it's a user definition. There are use-cases where t=0 is some "important reference time" in the middle of a simulation"

@theo-brown theo-brown deleted the imas-geometry-timeslice branch September 12, 2025 10:43
@theo-brown
Copy link
Collaborator Author

Ok, cool! Thanks for clarifying :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara:import-manual Set when ready for copybara manual import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants