Skip to content

Commit bd696c0

Browse files
committed
test for checking sensitivity analysis
1 parent 75eeb6d commit bd696c0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/test_sensitivity.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import hjson
2+
import pytest
3+
import numpy as np
4+
5+
from c3.optimizers.sensitivity import SET
6+
from c3.experiment import Experiment
7+
8+
OPT_CONFIG_FILE_NAME = "test/sensitivity.cfg"
9+
DESIRED_SWEEP_END_PARAMS = [-205000000.0, 5001500000.0]
10+
SWEEP_PARAM_NAMES = ["Q1-anhar", "Q1-freq"]
11+
12+
13+
@pytest.mark.integration
14+
@pytest.mark.slow
15+
def test_sensitivity() -> None:
16+
"""Test sensitivity analysis with 1D sweeps on 2 variables"""
17+
with open(OPT_CONFIG_FILE_NAME, "r") as cfg_file:
18+
cfg = hjson.load(cfg_file)
19+
20+
cfg.pop("optim_type")
21+
22+
exp = Experiment()
23+
exp.read_config(cfg.pop("exp_cfg"))
24+
25+
opt = SET(**cfg, pmap=exp.pmap)
26+
opt.set_exp(exp)
27+
opt.set_created_by(OPT_CONFIG_FILE_NAME)
28+
opt.run()
29+
30+
for index, val in enumerate(SWEEP_PARAM_NAMES):
31+
# This decomposition of opt.sweep_end into the actual_param_end only makes
32+
# sense when you look at how opt.sweep_end structures the sweep endings
33+
actual_param_end = opt.sweep_end[index][val]["params"][0]
34+
np.testing.assert_almost_equal(
35+
actual_param_end, DESIRED_SWEEP_END_PARAMS[index]
36+
)

0 commit comments

Comments
 (0)