From 31fbe30866a0db1e92cca235bbc03e01ec1e3437 Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Thu, 29 Jul 2021 16:30:19 -0400 Subject: [PATCH] Add a timing test for B12 --- interface/pybind11_wrapper.hpp | 1 + notebooks/time_Ar0n.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/interface/pybind11_wrapper.hpp b/interface/pybind11_wrapper.hpp index 13e7ff9..107c1a6 100644 --- a/interface/pybind11_wrapper.hpp +++ b/interface/pybind11_wrapper.hpp @@ -36,6 +36,7 @@ void add_derivatives(py::module &m, Wrapper &cls) { using vd = VirialDerivatives<Model, double, Eigen::Array<double,Eigen::Dynamic,1>>; m.def("get_B2vir", &vd::get_B2vir, py::arg("model"), py::arg("T"), py::arg("molefrac").noconvert()); + cls.def("get_B2vir", [](const Model& m, const double T, const RAX molefrac) { return vd::get_B2vir(m, T, molefrac); }, py::arg("T"), py::arg("molefrac").noconvert()); m.def("get_B12vir", &vd::get_B12vir, py::arg("model"), py::arg("T"), py::arg("molefrac").noconvert()); using ct = CriticalTracing<Model, double, Eigen::Array<double, Eigen::Dynamic, 1>>; diff --git a/notebooks/time_Ar0n.py b/notebooks/time_Ar0n.py index d16f6f6..fb13070 100644 --- a/notebooks/time_Ar0n.py +++ b/notebooks/time_Ar0n.py @@ -91,6 +91,30 @@ def time(*, model, n, Nrep, use_gen): elap = (toc-tic)/Nrep return elap +def time_virials(*, Ncomp, Nrep): + T = 300 + molefrac = np.array([1.0]) + + model = teqp.vdWEOS( + np.linspace(150.687, 160, Ncomp).tolist(), + np.linspace(4863000.0, 4.9e6, Ncomp).tolist() + ) + + f = getattr(model, f"get_B2vir") + # Warm up the core with some useless calls + for i in range(Nrep): + f(T, molefrac) + # Do the calculations + tic = timeit.default_timer() + for i in range(Nrep): + f(T, molefrac) + toc = timeit.default_timer() + elap = (toc-tic)/Nrep + return elap + +for Ncomp in np.arange(1, 20, 1): + print(Ncomp, time_virials(Nrep=10000, Ncomp=Ncomp)) + def timeall(*, models, Nrep): o = [] for use_gen in [True,False]: @@ -138,6 +162,7 @@ def timeall(*, models, Nrep): plt.close() if __name__ == '__main__': + timeall(models=build_models(), Nrep= 10000) def time_overhead(x): -- GitLab