-
Couldn't load subscription status.
- Fork 71
Overflow error in Mgrid write method #557
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
base: master
Are you sure you want to change the base?
Conversation
…llows for writing to 64bit arrays
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #557 +/- ##
=======================================
Coverage 92.56% 92.56%
=======================================
Files 83 83
Lines 16229 16229
=======================================
Hits 15023 15023
Misses 1206 1206
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I see that The question is thus whether VMEC can handle (read in) mgrid files which have been generated with this option (and next, whether our bound version of VMEC can). This I am pretty sure of, I know people who use insanely large MGRID resolutions. The input file handling of our bound VMEC should be similar to raw VMEC, as it just wraps and interfaces the Fortran routines. for safety, you should test if the mgrid file generated like this works with raw VMEC and on our bound version, and if it passes we can be confident there is no issue. If it fails on raw VMEC, it is an issue for them I would say. |
|
On quick look at the VMEC fortran source code, most of the integers used in mgrid code are 32 bit wide. Going for higher resolution may lead to failures. |
|
@mbkumar I believe that the problem is that the mgrid file is being written with the incorrect version argument. I am not 100% positive if the error is arising from the float type. One reason to suspect this is that DESC also writes mgrid files using the 64-bit offset format. Another is that the simsopt To get a better understanding of the problem, I am consulting with the DESC developers. |
|
Then I think the issue is using 32 bit floats in place of 64 bit doubles.
Bharat Medasani
…On Thu, Oct 16, 2025 at 9:31 AM Misha Padidar ***@***.***> wrote:
*mishapadidar* left a comment (hiddenSymmetries/simsopt#557)
<#557 (comment)>
@mbkumar <https://github.com/mbkumar> I believe that the problem is that
the mgrid file is being written with the incorrect version argument. I am
not 100% positive if the error is arising from the float type.
One reason to suspect this is that DESC also writes mgrid files
<https://github.com/PlasmaControl/DESC/blob/4e527932c898b6058a4134fe7e57157e37e80b78/desc/magnetic_fields/_core.py#L642>
using the 64-bit offset format.
Another is that the simsopt .write method cannot write files as large as
the ones often used in the community, such as the ones here
<https://www.osti.gov/servlets/purl/2458165>, unless we use the 64 bit
offset format.
To get a better understanding of the problem, I am consulting with the
DESC developers.
—
Reply to this email directly, view it on GitHub
<#557 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA62VEH2M475OXWYBHCAWKT3X6M3BAVCNFSM6AAAAACHNLWG62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMJQHEYDEOJWHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Summary
Using the
.writemethod of theMgridclass can lead to an Overflow error (see screenshot).Context
The
Mgridclass is used to writenetcdffiles which can be used in free boundary VMEC. When setting the resolution parameters of theMgridclass,nr, nphi, nz, to high values, thewritemethod can overflow (see screenshot)As seen in the screenshot, the write method attempts to write values to an array that is allocated for single precision. The error occurs because the values being written cannot be represented in 32 bits.
This overflow error is problematic because it limits users to only using coarse grids which poorly represent magnetic fields.
Fix
The
Mgridclass uses Scipy'snetcdf_fileclass to write the file. Thenetcdf_fileclass relies on theversionargument, which defaults toversion=1. Theversionargument sets the array format for writing, where 1 means Classic format (32 bit in our case) and 2 means 64-bit offset format. Switching theMgrid.writemethod to rely onnetcdf_file(... version=2)forces the values to be written to a 64-bit array, which solves the problem.Question/Uncertainty
While setting
version=2seems to prevent the overflow error from appearing, I do not understand the fortran side of the code well enough to know if this change will lead to misrepresentation of the magnetic fields in the Mgrid files. In other words, is using64-bit offset formatappropriate? Perhaps you have a better sense, @mbkumar @landreman.