Skip to content

Commit

Permalink
fix for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgiuliani committed Apr 19, 2024
1 parent 38a20cb commit ef394ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:

- name: Install simsopt package
# run: env CMAKE_BUILD_TYPE=Debug pip install -v .[MPI,SPEC]
run: pip install -v ".[MPI,SPEC,VIS]"
run: pip install -v ".[MPI,SPEC]"

- name: Verify that importing simsopt does not automatically initialize MPI
run: ./tests/verify_MPI_not_initialized.py
Expand Down
72 changes: 35 additions & 37 deletions tests/mhd/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,29 +138,28 @@ def test_set_profile_non_cumulative(self):

filename = os.path.join(TEST_DIR, 'RotatingEllipse_Nvol8.sp')

with ScratchDir("."):
s = Spec(filename)
nvol = s.inputlist.nvol
mvol = nvol + s.inputlist.lfreebound
s = Spec(filename)
nvol = s.inputlist.nvol
mvol = nvol + s.inputlist.lfreebound

cumulative = False # Surfaces currents are non-cumulative quantities in SPEC
surface_current = ProfileSpec(np.zeros((mvol,)), cumulative=cumulative)
cumulative = False # Surfaces currents are non-cumulative quantities in SPEC
surface_current = ProfileSpec(np.zeros((mvol,)), cumulative=cumulative)

s.interface_current_profile = surface_current
s.interface_current_profile = surface_current

# Check that all currents are actually zero
for lvol in range(1, mvol):
self.assertEqual(s.get_profile('interface_current', lvol), 0)
# Check that all currents are actually zero
for lvol in range(1, mvol):
self.assertEqual(s.get_profile('interface_current', lvol), 0)

# Modify one interface current
s.set_profile('interface_current', lvol=3, value=1)
# Modify one interface current
s.set_profile('interface_current', lvol=3, value=1)

# Check values
for lvol in range(1, mvol):
if lvol != 3:
self.assertEqual(s.get_profile('interface_current', lvol), 0)
else:
self.assertEqual(s.get_profile('interface_current', lvol), 1)
# Check values
for lvol in range(1, mvol):
if lvol != 3:
self.assertEqual(s.get_profile('interface_current', lvol), 0)
else:
self.assertEqual(s.get_profile('interface_current', lvol), 1)

def test_set_profile_cumulative(self):
"""
Expand All @@ -170,31 +169,30 @@ def test_set_profile_cumulative(self):

filename = os.path.join(TEST_DIR, 'RotatingEllipse_Nvol8.sp')

with ScratchDir("."):
s = Spec(filename)
nvol = s.inputlist.nvol
mvol = nvol + s.inputlist.lfreebound
s = Spec(filename)
nvol = s.inputlist.nvol
mvol = nvol + s.inputlist.lfreebound

cumulative = True # Surfaces currents are non-cumulative quantities in SPEC
volume_current = ProfileSpec(np.zeros((mvol,)), cumulative=cumulative)
cumulative = True # Surfaces currents are non-cumulative quantities in SPEC
volume_current = ProfileSpec(np.zeros((mvol,)), cumulative=cumulative)

s.volume_current_profile = volume_current
s.volume_current_profile = volume_current

# Check that all currents are actually zero
for lvol in range(1, mvol):
self.assertEqual(s.get_profile('volume_current', lvol), 0)
# Check that all currents are actually zero
for lvol in range(1, mvol):
self.assertEqual(s.get_profile('volume_current', lvol), 0)

# Modify one interface current
s.set_profile('volume_current', lvol=3, value=1)
# Modify one interface current
s.set_profile('volume_current', lvol=3, value=1)

print(s.volume_current_profile)
print(s.volume_current_profile)

# Check values
for lvol in range(1, mvol):
if lvol < 3:
self.assertEqual(s.get_profile('volume_current', lvol), 0)
else:
self.assertEqual(s.get_profile('volume_current', lvol), 1)
# Check values
for lvol in range(1, mvol):
if lvol < 3:
self.assertEqual(s.get_profile('volume_current', lvol), 0)
else:
self.assertEqual(s.get_profile('volume_current', lvol), 1)

def test_integrated_stellopt_scenarios_1dof(self):
"""
Expand Down

0 comments on commit ef394ae

Please sign in to comment.