From 205f69cbb4e445eb661b0097637f15ae2ffcec96 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Fri, 28 Jan 2022 11:43:36 +0100 Subject: [PATCH] [python] cleanup Engine getters/setters --- examples/python/actor-join/actor-join.py | 2 +- .../python/actor-suspend/actor-suspend.py | 2 +- .../clusters-multicpu/clusters-multicpu.py | 2 +- examples/python/exec-dvfs/exec-dvfs.py | 4 +- .../python/io-degradation/io-degradation.py | 6 +- .../platform-failures/platform-failures.py | 4 +- .../platform-profile/platform-profile.py | 2 +- src/bindings/python/simgrid_python.cpp | 59 ++++++++++++++++--- 8 files changed, 61 insertions(+), 20 deletions(-) diff --git a/examples/python/actor-join/actor-join.py b/examples/python/actor-join/actor-join.py index 470e2f8df0..38f209a652 100644 --- a/examples/python/actor-join/actor-join.py +++ b/examples/python/actor-join/actor-join.py @@ -55,4 +55,4 @@ if __name__ == '__main__': e.run() - this_actor.info("Simulation time {}".format(Engine.get_clock())) + this_actor.info("Simulation time {}".format(e.clock())) diff --git a/examples/python/actor-suspend/actor-suspend.py b/examples/python/actor-suspend/actor-suspend.py index 13f0200794..fae11b64e2 100644 --- a/examples/python/actor-suspend/actor-suspend.py +++ b/examples/python/actor-suspend/actor-suspend.py @@ -75,7 +75,7 @@ if __name__ == '__main__': "Usage: actor-suspend.py platform_file [other parameters]") e.load_platform(sys.argv[1]) # Load the platform description - hosts = e.get_all_hosts() + hosts = e.all_hosts Actor.create("dream_master", hosts[0], dream_master) e.run() # Run the simulation diff --git a/examples/python/clusters-multicpu/clusters-multicpu.py b/examples/python/clusters-multicpu/clusters-multicpu.py index 45312044ad..bf1a4d597e 100644 --- a/examples/python/clusters-multicpu/clusters-multicpu.py +++ b/examples/python/clusters-multicpu/clusters-multicpu.py @@ -289,7 +289,7 @@ if __name__ == '__main__': else: sys.exit("invalid param") - host_list = e.get_all_hosts() + host_list = e.all_hosts # create the sender actor running on first host simgrid.Actor.create("sender", host_list[0], Sender(host_list)) # create receiver in every host diff --git a/examples/python/exec-dvfs/exec-dvfs.py b/examples/python/exec-dvfs/exec-dvfs.py index aac901557c..6870b04feb 100644 --- a/examples/python/exec-dvfs/exec-dvfs.py +++ b/examples/python/exec-dvfs/exec-dvfs.py @@ -20,7 +20,7 @@ class Dvfs: # Run a task this_actor.execute(workload) - task_time = Engine.get_clock() + task_time = Engine.clock() this_actor.info("Task1 duration: {:.2f}".format(task_time)) # Change power peak @@ -35,7 +35,7 @@ class Dvfs: # Run a second task this_actor.execute(workload) - task_time = Engine.get_clock() - task_time + task_time = Engine.clock() - task_time this_actor.info("Task2 duration: {:.2f}".format(task_time)) # Verify that the default pstate is set to 0 diff --git a/examples/python/io-degradation/io-degradation.py b/examples/python/io-degradation/io-degradation.py index 1b955b57b7..72895e5add 100644 --- a/examples/python/io-degradation/io-degradation.py +++ b/examples/python/io-degradation/io-degradation.py @@ -22,14 +22,14 @@ import functools def estimate_bw(disk: Disk, n_flows: int, read: bool): """ Calculates the bandwidth for disk doing async operations """ size = 100000 - cur_time = Engine.get_clock() + cur_time = Engine.clock() activities = [disk.read_async(size) if read else disk.write_async( size) for _ in range(n_flows)] for act in activities: act.wait() - elapsed_time = Engine.get_clock() - cur_time + elapsed_time = Engine.clock() - cur_time estimated_bw = float(size * n_flows) / elapsed_time this_actor.info("Disk: %s, concurrent %s: %d, estimated bandwidth: %f" % ( disk.name, "read" if read else "write", n_flows, estimated_bw)) @@ -115,7 +115,7 @@ if __name__ == '__main__': Actor.create("runner", bob, host) e.run() - this_actor.info("Simulated time: %g" % Engine.get_clock()) + this_actor.info("Simulated time: %g" % Engine.clock()) # explicitly deleting Engine object to avoid segfault during cleanup phase. # During Engine destruction, the cleanup of std::function linked to non_linear callback is called. diff --git a/examples/python/platform-failures/platform-failures.py b/examples/python/platform-failures/platform-failures.py index 7ea66d3e97..e1aa136afd 100644 --- a/examples/python/platform-failures/platform-failures.py +++ b/examples/python/platform-failures/platform-failures.py @@ -99,7 +99,7 @@ if __name__ == '__main__': e.load_deployment(sys.argv[2]) # Add a new host programatically, and attach a state profile to it - lili = e.get_netzone_root().create_host("Lilibeth", 1e15) + lili = e.netzone_root.create_host("Lilibeth", 1e15) lili.set_state_profile("4 0\n5 1\n", 10) lili.seal() @@ -109,4 +109,4 @@ if __name__ == '__main__': e.run() - this_actor.info(f"Simulation time {e.get_clock():.4f}") + this_actor.info(f"Simulation time {e.clock():.4f}") diff --git a/examples/python/platform-profile/platform-profile.py b/examples/python/platform-profile/platform-profile.py index f4cf53b14e..1fb9611e1b 100644 --- a/examples/python/platform-profile/platform-profile.py +++ b/examples/python/platform-profile/platform-profile.py @@ -37,7 +37,7 @@ if __name__ == '__main__': e.load_platform(sys.argv[1]) # Add a new host programmatically, and attach a simple speed profile to it (alternate between full and half speed every two seconds - lili = e.get_netzone_root().create_host("Lilibeth", 25e6) + lili = e.netzone_root.create_host("Lilibeth", 25e6) lili.set_speed_profile("""0 1.0 2 0.5""", 2) lili.seal() diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index a875f1e4a0..9e33cabfa6 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -146,20 +146,61 @@ PYBIND11_MODULE(simgrid, m) return new simgrid::s4u::Engine(&argc, argv.data()); }), "The constructor should take the parameters from the command line, as is ") - .def_static("get_clock", &Engine::get_clock, + .def_static("get_clock", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_clock() is deprecated and will be dropped after v3.32, use clock() instead.", 1); + return self.attr("clock"); + }) + .def_static("clock", &Engine::get_clock, "The simulation time, ie the amount of simulated seconds since the simulation start.") .def_static( "instance", []() { return Engine::get_instance(); }, "Retrieve the simulation engine") - .def("get_all_hosts", &Engine::get_all_hosts, "Returns the list of all hosts found in the platform") - .def("get_all_links", &Engine::get_all_links, "Returns the list of all links found in the platform") - - .def("get_netzone_root", &Engine::get_netzone_root, "Retrieve the root netzone, containing all others.") - .def("get_all_netpoints", &Engine::get_all_netpoints) - .def("get_netzone_root", &Engine::get_netzone_root) + .def("get_all_hosts", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_all_hosts() is deprecated and will be dropped after v3.32, use all_host() instead.", 1); + return self.attr("all_hosts"); + }) + .def_property_readonly("all_hosts", &Engine::get_all_hosts, "Returns the list of all hosts found in the platform") + .def("get_all_links", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_all_links() is deprecated and will be dropped after v3.32, use all_links() instead.", + 1); + return self.attr("all_links"); + }) + .def_property_readonly("all_links", &Engine::get_all_links, "Returns the list of all links found in the platform") + .def("get_all_netpoints", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx( + PyExc_DeprecationWarning, + "get_all_netpoints() is deprecated and will be dropped after v3.32, use all_netpoints() instead.", 1); + return self.attr("all_netpoints"); + }) + .def_property_readonly("all_netpoints", &Engine::get_all_netpoints) + .def("get_netzone_root", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx( + PyExc_DeprecationWarning, + "get_netzone_root() is deprecated and will be dropped after v3.32, use netzone_root() instead.", 1); + return self.attr("netzone_root"); + }) + .def("set_netzone_root", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v333 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "set_netzone_root() is deprecated and will be dropped after v3.32.", 1); + }) + .def_property_readonly("netzone_root", &Engine::get_netzone_root, + "Retrieve the root netzone, containing all others.") .def("netpoint_by_name", &Engine::netpoint_by_name_or_null) .def("netzone_by_name", &Engine::netzone_by_name_or_null) - .def("set_netzone_root", &Engine::set_netzone_root) - .def("load_platform", &Engine::load_platform, "Load a platform file describing the environment") .def("load_deployment", &Engine::load_deployment, "Load a deployment file and launch the actors that it contains") .def("run", &Engine::run, py::call_guard(), "Run the simulation until its end") -- 2.20.1