def test_convergence_evaluation_single(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.43.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=43) s, c, t, i = cb.run_single_sample_from_sample_file(fname, name="Sample-1") assert c == True
def test_convergence_evaluation_fixedvar_mutableparam(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(currdir, 'ceval_fixedvar_mutableparam.3.43.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=43) inputs, samples, global_results = \ cb.run_convergence_evaluation_from_sample_file(fname) # put the results into a json file for comparison # jsondict = dict(inputs=inputs, samples=samples, # global_results=global_results) # results_fname = os.path.join( # currdir, 'ceval_fixedvar_mutableparam.3.43.results.json') # with open(results_fname, 'w') as fd: # json.dump(jsondict, fd, indent=3) # compare results assert global_results[0]['name'] == 'Sample-1' assert global_results[0]['solved'] # This should take 14 iterations to converge with the IDAES solver # distribution, but due to various solver factors the number of iterations # could vary. assert global_results[0]['iters'] == pytest.approx(14, abs=2) assert global_results[1]['name'] == 'Sample-2' assert global_results[1]['solved'] # This should take 15 iterations to converge with the IDAES solver # distribution, but due to various solver factors the number of iterations # could vary. assert global_results[1]['iters'] == pytest.approx(15, abs=2) assert global_results[2]['name'] == 'Sample-3' assert global_results[2]['solved'] # This should take 12 iterations to converge with the IDAES solver # distribution, but due to various solver factors the number of iterations # could vary. assert global_results[2]['iters'] == pytest.approx(12, abs=2) if os.path.exists(fname): os.remove(fname)
def test_convergence_evaluation_stats_from_to(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.43.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=43) inputs, samples, results = \ cb.run_convergence_evaluation_from_sample_file(fname) s = cb.save_convergence_statistics(inputs, results) d = s.to_dict() s2 = cb.Stats(from_dict=d) fname1 = os.path.join(wrtdir, 'stats1.json') fname2 = os.path.join(wrtdir, 'stats2.json') fname3 = os.path.join(wrtdir, 'stats3.json') with open(fname1, "w") as f: s.to_json(f) with open(fname2, "w") as f: s2.to_json(f) compare_json_files(baseline_fname=fname1, output_fname=fname2, tolerance=1e-8) s3 = cb.Stats(from_json=fname1) with open(fname3, "w") as f: s3.to_json(f) compare_json_files(baseline_fname=fname1, output_fname=fname3, tolerance=1e-8) if os.path.exists(fname): os.remove(fname) if os.path.exists(fname1): os.remove(fname1) if os.path.exists(fname2): os.remove(fname2) if os.path.exists(fname3): os.remove(fname3)
def test_convergence_evaluation_specification_file_fixedvar_mutableparam(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(currdir, 'ceval_fixedvar_mutableparam.3.42.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=42) baseline_fname = os.path.join( currdir, 'ceval_fixedvar_mutableparam.3.42.baseline.json') compare_json_files(baseline_fname=baseline_fname, output_fname=fname, tolerance=1e-8) if os.path.exists(fname): os.remove(fname)
def test_convergence_evaluation_fixedvar_mutableparam(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(currdir, 'ceval_fixedvar_mutableparam.3.43.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=43) inputs, samples, global_results = \ cb.run_convergence_evaluation_from_sample_file(fname) # put the results into a json file for comparison # jsondict = dict(inputs=inputs, samples=samples, # global_results=global_results) # results_fname = os.path.join( # currdir, 'ceval_fixedvar_mutableparam.3.43.results.json') # with open(results_fname, 'w') as fd: # json.dump(jsondict, fd, indent=3) # compare results assert global_results[0]['name'] == 'Sample-1' assert global_results[0]['solved'] assert global_results[0]['iters'] == 14 assert global_results[1]['name'] == 'Sample-2' assert global_results[1]['solved'] assert global_results[1]['iters'] == 15 assert global_results[2]['name'] == 'Sample-3' assert global_results[2]['solved'] assert global_results[2]['iters'] == 12 if os.path.exists(fname): os.remove(fname)
def test_convergence_evaluation_stats_from_to(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.43.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=43) inputs, samples, results = \ cb.run_convergence_evaluation_from_sample_file(fname) s = cb.save_convergence_statistics(inputs, results) d = s.to_dict() s2 = cb.Stats(from_dict=d) fname1 = os.path.join(wrtdir, 'stats1.json') with open(fname1, "w") as f: s.to_json(f) with open(fname1) as FILE: baseline = json.load(FILE) buf = io.StringIO() s2.to_json(buf) test = json.loads(buf.getvalue()) assertStructuredAlmostEqual(baseline, test, abstol=1e-8) s3 = cb.Stats(from_json=fname1) buf = io.StringIO() s3.to_json(buf) test = json.loads(buf.getvalue()) assertStructuredAlmostEqual(baseline, test, abstol=1e-8) if os.path.exists(fname): os.remove(fname) if os.path.exists(fname1): os.remove(fname1)
def test_convergence_evaluation_specification_file_fixedvar_mutableparam(): ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str) ceval = ceval_class() import idaes.core.util.convergence.tests.conv_eval_classes as cev assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__ spec = ceval.get_specification() fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.42.json') cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str, n_points=3, seed=42) baseline_fname = os.path.join( currdir, 'ceval_fixedvar_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) if os.path.exists(fname): os.remove(fname)