Skip to content
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

Attribute types are not always correct #1029

Closed
ddudt opened this issue May 22, 2024 · 1 comment · Fixed by #1030
Closed

Attribute types are not always correct #1029

ddudt opened this issue May 22, 2024 · 1 comment · Fixed by #1030
Assignees
Labels
bug Something isn't working easy Short and simple to code or review

Comments

@ddudt
Copy link
Collaborator

ddudt commented May 22, 2024

Some class attributes are not always the intended data type. For example, Equilibrium.NFP is supposed to be an int but in the past it was sometimes a float. More recently, I discovered that Equilibrium.sym was of type numpy.bool_ instead of the python bool, which is treated differently by the pytree utility functions we use in the coil objectives. I recommend we cast to the intended data type in class getter methods to ensure the returned type is always correct.

@ddudt ddudt added bug Something isn't working easy Short and simple to code or review labels May 22, 2024
@ddudt ddudt self-assigned this May 22, 2024
@ddudt
Copy link
Collaborator Author

ddudt commented Jun 13, 2024

MWE to reproduce this type of error:

from desc.coils import *
from desc.io import load
from desc.objectives import *

# this is the DummyMixedCoilSet
tf_coil = FourierPlanarCoil(current=3, center=[2, 0, 0], normal=[0, 1, 0], r_n=[1])
tf_coilset = CoilSet.linspaced_angular(tf_coil, n=4)
vf_coil = FourierRZCoil(current=-1, R_n=3, Z_n=-1)
vf_coilset = CoilSet.linspaced_linear(
    vf_coil, displacement=[0, 0, 2], n=3, endpoint=True
)
xyz_coil = FourierXYZCoil(current=2)
coilset_1 = MixedCoilSet((tf_coilset, vf_coilset, xyz_coil))
coilset_1.save("dummy_mixed_coilset.h5")
coilset_2 = load("dummy_mixed_coilset.h5")

objective = ObjectiveFunction(
    (CoilLength(coils=coilset_2), CoilCurvature(coil=coilset_2))
)
objective.build()  # raises an AttributeError

The objective build works for coilset_1 but not coilset_2, so the data type is somehow changing in the save/load process.

@ddudt ddudt mentioned this issue Jun 13, 2024
ddudt added a commit that referenced this issue Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy Short and simple to code or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant