コード例 #1
0
def test_convergence_evaluation_specification_file_unfixedvar_mutableparam():
    ceval_class = cb._class_import(ceval_unfixedvar_mutableparam_str)
    ceval = ceval_class()
    import idaes.core.util.convergence.tests.conv_eval_classes as cev
    assert ceval.__class__ == cev.ConvEvalUnfixedVarMutableParam().__class__

    spec = ceval.get_specification()
    fname = os.path.join(currdir, 'ceval_unfixedvar_mutableparam.3.42.json')
    cb.write_sample_file(spec,
                         fname,
                         ceval_unfixedvar_mutableparam_str,
                         n_points=3,
                         seed=42)

    baseline_fname = os.path.join(
        currdir, 'ceval_unfixedvar_mutableparam.3.42.baseline.json')
    compare_json_files(baseline_fname=baseline_fname,
                       output_fname=fname,
                       tolerance=1e-8)

    # expect an exception because var is not fixed
    with pytest.raises(ValueError):
        inputs, samples, global_results = \
            cb.run_convergence_evaluation_from_sample_file(fname)

    if os.path.exists(fname):
        os.remove(fname)
コード例 #2
0
def test_convergence_evaluation_specification_file_unfixedvar_mutableparam():
    ceval_class = cb._class_import(ceval_unfixedvar_mutableparam_str)
    ceval = ceval_class()
    import idaes.core.util.convergence.tests.conv_eval_classes as cev
    assert ceval.__class__ == cev.ConvEvalUnfixedVarMutableParam().__class__

    spec = ceval.get_specification()
    fname = os.path.join(wrtdir, 'ceval_unfixedvar_mutableparam.3.42.json')
    cb.write_sample_file(spec, fname,
                         ceval_unfixedvar_mutableparam_str,
                         n_points=3, seed=42)

    baseline_fname = os.path.join(
            currdir,
            'ceval_unfixedvar_mutableparam.3.42.baseline.json')

    with open(fname) as FILE:
        test = json.load(FILE)
    with open(baseline_fname) as FILE:
        baseline = json.load(FILE)
    assertStructuredAlmostEqual(baseline, test, abstol=1e-8)

    # expect an exception because var is not fixed
    with pytest.raises(ValueError):
        inputs, samples, global_results = \
            cb.run_convergence_evaluation_from_sample_file(fname)

    if os.path.exists(fname):
        os.remove(fname)