def test_parameter_to_csv(tmpdir): csv_path = tmpdir.join("parameters.csv") params = ParameterGroup.from_yaml(""" b: - ["1", 0.25, {vary: false, min: 0, max: 8}] - ["2", 0.75, {expr: '1 - $b.1', non-negative: true}] rates: - ["total", 2] - ["branch1", {expr: '$rates.total * $b.1'}] - ["branch2", {expr: '$rates.total * $b.2'}] """) params.to_csv(csv_path) with open(csv_path) as f: print(f.read()) params_from_csv = ParameterGroup.from_csv(csv_path) for label, p in params.all(): assert params_from_csv.has(label) p_from_csv = params_from_csv.get(label) assert p.label == p_from_csv.label assert p.value == p_from_csv.value assert p.minimum == p_from_csv.minimum assert p.maximum == p_from_csv.maximum assert p.vary == p_from_csv.vary assert p.non_negative == p_from_csv.non_negative assert p.expression == p_from_csv.expression
def test_param_group_from_csv(tmpdir): csv_path = tmpdir.join("parameters.csv") with open(csv_path, "w") as f: f.write(TEST_CSV) params = ParameterGroup.from_csv(csv_path) assert "rates" in params assert params.has("rates.k1") p = params.get("rates.k1") assert p.label == "k1" assert p.value == 0.05 assert p.minimum == 0 assert p.maximum == 5 assert p.vary assert p.non_negative assert p.expression is None assert params.has("rates.k2") p = params.get("rates.k2") assert p.label == "k2" assert p.value == params.get("rates.k1") * 2 assert p.minimum == -np.inf assert p.maximum == np.inf assert not p.vary assert not p.non_negative assert p.expression == "$rates.k1 * 2" assert params.has("rates.k3") p = params.get("rates.k3") assert p.label == "k3" assert p.value == 2.311 assert p.minimum == -np.inf assert p.maximum == np.inf assert p.vary assert p.non_negative assert p.expression is None assert "pen" in params assert "eq" in params["pen"] assert params.has("pen.eq.1") p = params.get("pen.eq.1") assert p.label == "1" assert p.value == 1.0 assert p.minimum == -np.inf assert p.maximum == np.inf assert not p.vary assert not p.non_negative assert p.expression is None