Skip to content

Commit

Permalink
Density and Energy test (#38)
Browse files Browse the repository at this point in the history
* tests for kappa eh, and checked LB conserves energy and density

* code cleanup

* the density and energy test
  • Loading branch information
joglekara authored Mar 12, 2024
1 parent 27871b2 commit b4bec67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ boto3
pint
mlflow_export_import
plasmapy
tabulate
tabulate
interpax
21 changes: 18 additions & 3 deletions tests/test_vfp1d/test_kappa_eh.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import os, yaml, mlflow, numpy as np, pytest
import os, yaml, mlflow, numpy as np, pytest

from utils.runner import run


def _run_(Z, ee):
def _run_(Z, ee):
# with open("configs/tf-1d/damping.yaml", "r") as fi:
with open(f"{os.path.join(os.getcwd(), 'tests/test_vfp1d/epp-short')}.yaml", "r") as fi:
cfg = yaml.safe_load(fi)

cfg["units"]["Z"] = Z

if ee:
cfg["terms"]["fokker_planck"]["flm"]["ee"] = True
cfg["grid"]["nv"] = 2048


if ee:
cfg["terms"]["fokker_planck"]["flm"]["ee"] = True
cfg["grid"]["nv"] = 2048
Expand All @@ -19,13 +26,21 @@ def _run_(Z, ee):
with mlflow.start_run(run_name=cfg["mlflow"]["run"]) as mlflow_run:
result, datasets = run(cfg)

dataT = datasets["fields"]["fields-T keV"].data
np.testing.assert_almost_equal(np.mean(dataT[-4, :]), np.mean(dataT[4, :]), decimal=5)

datan = datasets["fields"]["fields-n n_c"].data
np.testing.assert_almost_equal(np.mean(datan[-4, :]), np.mean(datan[4, :]), decimal=5)

kappa_eh = mlflow.get_run(mlflow_run.info.run_id).data.metrics["kappa_eh"]
kappa = mlflow.get_run(mlflow_run.info.run_id).data.metrics["kappa"]
return kappa, kappa_eh

np.testing.assert_almost_equal(kappa, kappa_eh, decimal=0)

return mlflow_run.info.run_id


@pytest.mark.parametrize("Z", list(range(1, 21, 4)) + [40, 60, 80])
@pytest.mark.parametrize("ee", [True, False])
def test_kappa_eh(Z, ee):
kappa, kappa_eh = _run_(Z, ee)
np.testing.assert_almost_equal(kappa, kappa_eh, decimal=0)
_run_(Z, ee)

0 comments on commit b4bec67

Please sign in to comment.