Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,6 @@ examples/mesh_plot/
thincurr_scratch/
scratch/
synthwave/vessel_caches

# No figure storage to git, at least of pdfs
*.pdf
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ repos:
entry: uv run jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace
- id: ruff_format
name: ruff_format
entry: uv run ruff format
entry: uv run --no-sync ruff format
language: system
types: [python]
files: "^synthwave/"
- id: ruff_check
name: ruff_check
entry: uv run ruff check --fix
entry: uv run --no-sync ruff check --fix
language: system
types: [python]
files: "^synthwave/"
- id: isort
name: isort
entry: uv run isort
entry: uv run --no-sync isort
language: system
types: [python]
files: "^synthwave/"
Binary file added alpha_lhs_new.pdf
Binary file not shown.
Binary file added alpha_new.pdf
Binary file not shown.
Binary file added alpha_old.pdf
Binary file not shown.
Binary file added alpha_rhs_new.pdf
Binary file not shown.
Binary file added eBp_mew_alpha.pdf
Binary file not shown.
Binary file added eBp_old_alpha.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions synthwave/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gc

import pytest
from OpenFUSIONToolkit import OFT_env


def pytest_configure(config):
Expand All @@ -27,3 +28,9 @@ def _serial_gc(request):
yield
if request.node.get_closest_marker("serial"):
gc.collect()


# Fixture for OFT environment so only one is created for all tests.
@pytest.fixture(scope="session")
def oft_env():
return OFT_env(nthreads=2)
13 changes: 5 additions & 8 deletions synthwave/tests/test_direct_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
import pytest
import xarray as xr
from OpenFUSIONToolkit import OFT_env

from synthwave import PACKAGE_ROOT
from synthwave.magnetic_geometry.equilibrium_field import (
Expand All @@ -35,7 +34,10 @@
direct_response_thincurr,
)

# ThinCurr / OFT_env hold global C++ state that cannot be shared across workers
# All tests in this file use the OpenFUSIONToolkit C++ library which has
# global state (OFT_env, ThinCurr) that cannot be shared across concurrent
# workers. Mark the entire module serial so the conftest fixture forces
# sequential execution and GC cleanup between tests.
pytestmark = pytest.mark.serial

_CMOD_DIR = os.path.join(PACKAGE_ROOT, "input_data", "cmod")
Expand All @@ -48,11 +50,6 @@
_BASE_NUM_POINTS = 100


@pytest.fixture(scope="module")
def oft_env():
return OFT_env(nthreads=2)


@pytest.fixture(scope="module")
def sensor_details():
"""Load the C-Mod Mirnov set and conform it to the OFT/Biot-Savart schema.
Expand Down Expand Up @@ -169,7 +166,7 @@ def test_thincurr_phase_matches_biot_savart(oft_env, direct_response_inputs):
gen_OFT_filament_and_eta_file(
working_directory=tmpdir,
filament_list=filament_list,
resistivity_list=[1e-6] * len(filament_list),
resistivity_list=[1e-6],
)
sensor_file_path = gen_OFT_sensors_file(
sensor_details=sensor_details,
Expand Down
72 changes: 69 additions & 3 deletions synthwave/tests/test_equilibrium_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ def test_detect_cocos_cmod(self, eqdsk_cmod):
f"Expected COCOS {expected_cocos} for C-Mod, got {cocos}"
)

@pytest.mark.skipif(
condition=not os.path.exists(
os.path.join(
PACKAGE_ROOT,
"..",
"submodules",
"OpenFUSIONToolkit",
"examples",
"TokaMaker",
"DIIID",
"g192185.02440",
)
),
reason="Test requires DIII-D data which is not open source",
)
def test_detect_cocos_d3d(self, eqdsk_d3d):
"""DIII-D uses EFIT convention (sigma_RphiZ=+1, e_Bp=0, psi increasing).
COCOS depends on sign(Ip) and sign(B0)
Expand Down Expand Up @@ -345,7 +360,24 @@ def eqdsk(self, request):
"eqdsk",
[
"eqdsk_cmod",
"eqdsk_d3d",
pytest.param(
"eqdsk_d3d",
marks=pytest.mark.skipif(
condition=not os.path.exists(
os.path.join(
PACKAGE_ROOT,
"..",
"submodules",
"OpenFUSIONToolkit",
"examples",
"TokaMaker",
"DIIID",
"g192185.02440",
)
),
reason="Test requires DIII-D data which is not open source",
),
),
pytest.param(
"eqdsk_tcv",
marks=pytest.mark.skipif(
Expand Down Expand Up @@ -392,7 +424,24 @@ def test_convert_cocos_same(self, eqdsk):
"eqdsk",
[
"eqdsk_cmod",
"eqdsk_d3d",
pytest.param(
"eqdsk_d3d",
marks=pytest.mark.skipif(
condition=not os.path.exists(
os.path.join(
PACKAGE_ROOT,
"..",
"submodules",
"OpenFUSIONToolkit",
"examples",
"TokaMaker",
"DIIID",
"g192185.02440",
)
),
reason="Test requires DIII-D data which is not open source",
),
),
pytest.param(
"eqdsk_tcv",
marks=pytest.mark.skipif(
Expand Down Expand Up @@ -449,7 +498,24 @@ def test_convert_cocos_internal(self, eqdsk):
"eqdsk",
[
"eqdsk_cmod",
"eqdsk_d3d",
pytest.param(
"eqdsk_d3d",
marks=pytest.mark.skipif(
condition=not os.path.exists(
os.path.join(
PACKAGE_ROOT,
"..",
"submodules",
"OpenFUSIONToolkit",
"examples",
"TokaMaker",
"DIIID",
"g192185.02440",
)
),
reason="Test requires DIII-D data which is not open source",
),
),
pytest.param(
"eqdsk_tcv",
marks=pytest.mark.skipif(
Expand Down
22 changes: 6 additions & 16 deletions synthwave/tests/test_thincurr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pytest
import xarray as xr
from OpenFUSIONToolkit import OFT_env
from sympy import nextprime

from synthwave import PACKAGE_ROOT
Expand All @@ -31,13 +30,6 @@
pytestmark = pytest.mark.serial


# Fixture for oft environment so only one is created for all tests
@pytest.fixture(scope="session")
def oft_env_fixture():
oft_env = OFT_env(nthreads=2)
return oft_env


@pytest.mark.parametrize(
"mode",
[
Expand All @@ -49,7 +41,7 @@ def oft_env_fixture():
],
ids=["m2n1", "m3n2", "m-3n2", "m3n1", "m4n3"],
)
def test_toroidal_angles(mode, oft_env_fixture):
def test_toroidal_angles(mode, oft_env):
tolerance_tight = np.deg2rad(1)
tolerance_loose = np.deg2rad(
5
Expand Down Expand Up @@ -171,7 +163,7 @@ def test_toroidal_angles(mode, oft_env_fixture):
)

total_response, direct_response, _vessel_response = frequency_response_thincurr(
oft_env=oft_env_fixture,
oft_env=oft_env,
tracer=toroidal_tracer,
freq=10e3,
mesh_file=torus_mesh_file,
Expand Down Expand Up @@ -317,7 +309,7 @@ def test_gen_OFT_sensors_file():
assert len(content) > 0


def test_direct_response_thincurr_matches_frequency_response(oft_env_fixture):
def test_direct_response_thincurr_matches_frequency_response(oft_env):
"""direct_response_thincurr must return the same direct component as frequency_response_thincurr."""

major_radius = 1
Expand Down Expand Up @@ -370,13 +362,11 @@ def test_direct_response_thincurr_matches_frequency_response(oft_env_fixture):
filament_list, current_list = toroidal_tracer.get_filament_list(
num_filaments=num_filaments
)
gen_OFT_filament_and_eta_file(
working_directory, filament_list, [1e-6] * len(filament_list)
)
gen_OFT_filament_and_eta_file(working_directory, filament_list, [1e-6])

total_response, direct_response_freq, vessel_response = (
frequency_response_thincurr(
oft_env=oft_env_fixture,
oft_env=oft_env,
tracer=toroidal_tracer,
freq=10e3,
mesh_file=torus_mesh_file,
Expand All @@ -386,7 +376,7 @@ def test_direct_response_thincurr_matches_frequency_response(oft_env_fixture):
)

direct_response_only = direct_response_thincurr(
oft_env=oft_env_fixture,
oft_env=oft_env,
tracer=toroidal_tracer,
mesh_file=torus_mesh_file,
sensor_details=sensor_details,
Expand Down
Loading