From 3c19254bcc639fa7d14122d705a6bf977411137f Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Fri, 28 Jan 2022 14:44:15 +0100 Subject: [PATCH] more attributes in python bindings --- docs/source/app_s4u.rst | 11 +-- .../clusters-multicpu/clusters-multicpu.py | 4 +- examples/python/exec-dvfs/exec-dvfs.py | 6 +- .../network-nonlinear/network-nonlinear.py | 10 +-- src/bindings/python/simgrid_python.cpp | 90 +++++++++++++++---- teshsuite/python/platform-mix/platform-mix.py | 16 ++-- 6 files changed, 97 insertions(+), 40 deletions(-) diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index cdb1b5c602..8b5149f3f6 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -1298,7 +1298,7 @@ Modifying characteristics .. group-tab:: Python - .. automethod:: simgrid.Host.set_core_count + .. autoattribute:: simgrid.Host.core_count .. automethod:: simgrid.Host.set_coordinates .. automethod:: simgrid.Host.set_sharing_policy @@ -1319,6 +1319,7 @@ Querying info .. group-tab:: Python .. autoattribute:: simgrid.Host.name + .. autoattribute:: simgrid.Host.core_count .. autoattribute:: simgrid.Host.load .. autoattribute:: simgrid.Host.pstate .. autoattribute:: simgrid.Host.speed @@ -1404,8 +1405,8 @@ DVFS .. group-tab:: Python - .. automethod:: simgrid.Host.get_pstate_count - .. automethod:: simgrid.Host.get_pstate_speed + .. autoattribute:: simgrid.Host.pstate_count + .. automethod:: simgrid.Host.pstate_speed .. group-tab:: C @@ -1460,7 +1461,7 @@ using :cpp:func:`Comm::sendto() `. .. group-tab:: Python - .. automethod:: simgrid.Host.get_netpoint + .. autoattribute:: simgrid.Host.netpoint .. automethod:: simgrid.Host.create_disk .. automethod:: simgrid.Host.route_to @@ -1779,7 +1780,7 @@ Querying info .. group-tab:: Python .. autoattribute:: simgrid.NetZone.name - .. automethod:: simgrid.NetZone.get_netpoint + .. autoattribute:: simgrid.NetZone.netpoint .. group-tab:: C diff --git a/examples/python/clusters-multicpu/clusters-multicpu.py b/examples/python/clusters-multicpu/clusters-multicpu.py index bf1a4d597e..8673890e6a 100644 --- a/examples/python/clusters-multicpu/clusters-multicpu.py +++ b/examples/python/clusters-multicpu/clusters-multicpu.py @@ -103,12 +103,12 @@ def create_hostzone(zone: simgrid.NetZone, coord: typing.List[int], ident: int) link = host_zone.create_split_duplex_link("link-" + cpu_name, link_bw) link.set_latency(link_lat).seal() # connecting CPU to outer world - host_zone.add_route(host.get_netpoint(), None, None, None, [ + host_zone.add_route(host.netpoint, None, None, None, [ simgrid.LinkInRoute(link, simgrid.LinkInRoute.Direction.UP)], True) # seal newly created netzone host_zone.seal() - return host_zone.get_netpoint(), gateway.get_netpoint() + return host_zone.netpoint, gateway.netpoint ##################################################################################################### diff --git a/examples/python/exec-dvfs/exec-dvfs.py b/examples/python/exec-dvfs/exec-dvfs.py index 2b22bef6a4..7a7a5dd709 100644 --- a/examples/python/exec-dvfs/exec-dvfs.py +++ b/examples/python/exec-dvfs/exec-dvfs.py @@ -12,7 +12,7 @@ class Dvfs: workload = 100E6 host = this_actor.get_host() - nb = host.get_pstate_count() + nb = host.pstate_count this_actor.info("Count of Processor states={:d}".format(nb)) this_actor.info("Current power peak={:f}".format(host.speed)) @@ -26,7 +26,7 @@ class Dvfs: # Change power peak new_pstate = 2 - this_actor.info("Changing power peak value to {:f} (at index {:d})".format( host.get_pstate_speed(new_pstate), new_pstate)) + this_actor.info("Changing power peak value to {:f} (at index {:d})".format( host.pstate_speed(new_pstate), new_pstate)) host.pstate = new_pstate @@ -40,7 +40,7 @@ class Dvfs: # Verify that the default pstate is set to 0 host2 = Host.by_name("MyHost2") - this_actor.info("Count of Processor states={:d}".format(host2.get_pstate_count())) + this_actor.info("Count of Processor states={:d}".format(host2.pstate_count)) this_actor.info("Final power peak={:f}".format(host2.speed)) diff --git a/examples/python/network-nonlinear/network-nonlinear.py b/examples/python/network-nonlinear/network-nonlinear.py index 66a4a97b78..e8f2de6259 100644 --- a/examples/python/network-nonlinear/network-nonlinear.py +++ b/examples/python/network-nonlinear/network-nonlinear.py @@ -96,16 +96,16 @@ def load_platform(): link = zone.create_split_duplex_link("link1", 1e6) # setting same callbacks (could be different) for link UP/DOWN in split-duplex link - link.get_link_up().set_sharing_policy( + link.link_up.set_sharing_policy( Link.SharingPolicy.NONLINEAR, - functools.partial(link_nonlinear, link.get_link_up())) - link.get_link_down().set_sharing_policy( + functools.partial(link_nonlinear, link.link_up)) + link.link_down.set_sharing_policy( Link.SharingPolicy.NONLINEAR, - functools.partial(link_nonlinear, link.get_link_down())) + functools.partial(link_nonlinear, link.link_down)) link.set_latency(10e-6).seal() # create routes between nodes - zone.add_route(sender.get_netpoint(), receiver.get_netpoint(), None, None, + zone.add_route(sender.netpoint, receiver.netpoint, None, None, [LinkInRoute(link, LinkInRoute.Direction.UP)], True) zone.seal() diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 1153a250cc..81ca2895b1 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -150,7 +150,7 @@ PYBIND11_MODULE(simgrid, m) [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 { PyErr_WarnEx(PyExc_DeprecationWarning, - "get_clock() is deprecated and will be dropped after v3.33, use clock() instead.", 1); + "get_clock() is deprecated and will be dropped after v3.33, use clock instead.", 1); return self.attr("clock"); }) .def_property_readonly_static( @@ -162,7 +162,7 @@ PYBIND11_MODULE(simgrid, m) [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 { PyErr_WarnEx(PyExc_DeprecationWarning, - "get_all_hosts() is deprecated and will be dropped after v3.33, use all_host() instead.", 1); + "get_all_hosts() is deprecated and will be dropped after v3.33, use all_hosts 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") @@ -170,8 +170,7 @@ PYBIND11_MODULE(simgrid, m) [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 { PyErr_WarnEx(PyExc_DeprecationWarning, - "get_all_links() is deprecated and will be dropped after v3.33, use all_links() instead.", - 1); + "get_all_links() is deprecated and will be dropped after v3.33, 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") @@ -180,16 +179,16 @@ PYBIND11_MODULE(simgrid, m) { PyErr_WarnEx( PyExc_DeprecationWarning, - "get_all_netpoints() is deprecated and will be dropped after v3.33, use all_netpoints() instead.", 1); + "get_all_netpoints() is deprecated and will be dropped after v3.33, 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_v334 { - PyErr_WarnEx( - PyExc_DeprecationWarning, - "get_netzone_root() is deprecated and will be dropped after v3.3, use netzone_root() instead.", 1); + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_netzone_root() is deprecated and will be dropped after v3.3, use netzone_root instead.", + 1); return self.attr("netzone_root"); }) .def_property_readonly("netzone_root", &Engine::get_netzone_root, @@ -277,7 +276,15 @@ PYBIND11_MODULE(simgrid, m) .def("create_router", &simgrid::s4u::NetZone::create_router, "Create a router") .def("set_parent", &simgrid::s4u::NetZone::set_parent, "Set the parent of this zone") .def("set_property", &simgrid::s4u::NetZone::set_property, "Add a property to this zone") - .def("get_netpoint", &simgrid::s4u::NetZone::get_netpoint, "Retrieve the netpoint associated to this zone") + .def("get_netpoint", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_netpoint() is deprecated and will be dropped after v3.33, use netpoint instead.", 1); + return self.attr("netpoint"); + }) + .def_property_readonly("netpoint", &simgrid::s4u::NetZone::get_netpoint, + "Retrieve the netpoint associated to this zone") .def("seal", &simgrid::s4u::NetZone::seal, "Seal this NetZone") .def_property_readonly( "name", [](const simgrid::s4u::NetZone* self) { return self->get_name(); }, @@ -348,12 +355,49 @@ PYBIND11_MODULE(simgrid, m) " \"\"\"\n\n" "The second function parameter is the periodicity: the time to wait after the last event to start again over " "the list. Set it to -1 to not loop over.") - .def("get_pstate_count", &Host::get_pstate_count, "Retrieve the count of defined pstate levels") - .def("get_pstate_speed", &Host::get_pstate_speed, "Retrieve the maximal speed at the given pstate") - .def("get_netpoint", &Host::get_netpoint, "Retrieve the netpoint associated to this host") + .def("get_pstate_count", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx( + PyExc_DeprecationWarning, + "get_pstate_count() is deprecated and will be dropped after v3.33, use pstate_count instead.", 1); + return self.attr("pstate_count"); + }) + .def_property_readonly("pstate_count", &Host::get_pstate_count, "Retrieve the count of defined pstate levels") + .def("get_pstate_speed", + [](pybind11::object& self, int state) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx( + PyExc_DeprecationWarning, + "get_pstate_speed() is deprecated and will be dropped after v3.33, use pstate_speed instead.", 1); + return self.attr("pstate_speed")(state); + }) + .def("pstate_speed", &Host::get_pstate_speed, py::call_guard(), + "Retrieve the maximal speed at the given pstate") + .def("get_netpoint", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_netpoint() is deprecated and will be dropped after v3.33, use netpoint instead.", 1); + return self.attr("netpoint"); + }) + .def_property_readonly("netpoint", &Host::get_netpoint, "Retrieve the netpoint associated to this zone") .def("get_disks", &Host::get_disks, "Retrieve the list of disks in this host") - .def("set_core_count", &Host::set_core_count, py::call_guard(), - "Set the number of cores in the CPU") + .def("set_core_count", + [](pybind11::object& self, double count) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "set_core_count() is deprecated and will be dropped after v3.33, use core_count instead.", + 1); + self.attr("core_count")(count); + }) + .def_property( + "core_count", &Host::get_core_count, + [](Host* h, int count) { + py::gil_scoped_release gil_guard; + return h->set_core_count(count); + }, + "Manage the number of cores in the CPU") .def("set_coordinates", &Host::set_coordinates, py::call_guard(), "Set the coordinates of this host") .def("set_sharing_policy", &simgrid::s4u::Host::set_sharing_policy, py::call_guard(), @@ -551,8 +595,22 @@ PYBIND11_MODULE(simgrid, m) /* Class Split-Duplex Link */ py::class_>( m, "SplitDuplexLink", "Network split-duplex link") - .def("get_link_up", &simgrid::s4u::SplitDuplexLink::get_link_up, "Get link direction up") - .def("get_link_down", &simgrid::s4u::SplitDuplexLink::get_link_down, "Get link direction down"); + .def("get_link_up", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_link_up() is deprecated and will be dropped after v3.33, use link_up instead.", 1); + return self.attr("link_up"); + }) + .def_property_readonly("link_up", &simgrid::s4u::SplitDuplexLink::get_link_up, "Get link direction up") + .def("get_link_down", + [](pybind11::object& self) // XBT_ATTRIB_DEPRECATED_v334 + { + PyErr_WarnEx(PyExc_DeprecationWarning, + "get_link_down() is deprecated and will be dropped after v3.33, use link_down instead.", 1); + return self.attr("link_down"); + }) + .def_property_readonly("link_down", &simgrid::s4u::SplitDuplexLink::get_link_down, "Get link direction down"); /* Class Mailbox */ py::class_>( diff --git a/teshsuite/python/platform-mix/platform-mix.py b/teshsuite/python/platform-mix/platform-mix.py index dfdd040c26..57b235826a 100644 --- a/teshsuite/python/platform-mix/platform-mix.py +++ b/teshsuite/python/platform-mix/platform-mix.py @@ -53,7 +53,8 @@ def load_platform(): msg_base = "Creating zone: " this_actor.info(msg_base + dijkstra.name) dijkstra.set_parent(root) - host1 = dijkstra.create_host("host1", [1e9, 1e8]).set_core_count(2) + host1 = dijkstra.create_host("host1", [1e9, 1e8]) + host1.core_count = 2 hosts.append(host1) host1.create_disk("disk1", 1e5, 1e4).seal() host1.create_disk("disk2", "1MBps", "1Mbps").seal() @@ -62,8 +63,8 @@ def load_platform(): hosts.append(host2) link1 = dijkstra.create_link("link1_up", [1e9]).set_latency(1e-3).set_concurrency_limit(10).seal() link2 = dijkstra.create_link("link1_down", ["1GBps"]).set_latency("1ms").seal() - dijkstra.add_route(host1.get_netpoint(), host2.get_netpoint(), None, None, [LinkInRoute(link1)], False) - dijkstra.add_route(host2.get_netpoint(), host1.get_netpoint(), None, None, [LinkInRoute(link2)], False) + dijkstra.add_route(host1.netpoint, host2.netpoint, None, None, [LinkInRoute(link1)], False) + dijkstra.add_route(host2.netpoint, host1.netpoint, None, None, [LinkInRoute(link2)], False) dijkstra.seal() # vivaldi @@ -100,12 +101,9 @@ def load_platform(): link_a = vivaldi.create_link("linkA", 1e9).seal() link_b = vivaldi.create_link("linkB", "1GBps").seal() link_c = vivaldi.create_link("linkC", "1GBps").seal() - root.add_route(dijkstra.get_netpoint(), vivaldi.get_netpoint( - ), host1.get_netpoint(), host3.get_netpoint(), [LinkInRoute(link_a)], True) - root.add_route(vivaldi.get_netpoint(), empty.get_netpoint( - ), host3.get_netpoint(), host5.get_netpoint(), [LinkInRoute(link_b)], True) - root.add_route(empty.get_netpoint(), wifi.get_netpoint( - ), host5.get_netpoint(), router, [LinkInRoute(link_c)], True) + root.add_route(dijkstra.netpoint, vivaldi.netpoint, host1.netpoint, host3.netpoint, [LinkInRoute(link_a)], True) + root.add_route(vivaldi.netpoint, empty.netpoint, host3.netpoint, host5.netpoint, [LinkInRoute(link_b)], True) + root.add_route(empty.netpoint, wifi.netpoint, host5.netpoint, router, [LinkInRoute(link_c)], True) # create actors Sender/Receiver Actor.create("sender", hosts[0], Sender(hosts)) -- 2.20.1