From 444bae311b5e7581b17444ba7c94c28249b16cc1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 23 Jan 2022 02:19:43 +0100 Subject: [PATCH] Implement the last (?) Python functions needed for the tutorial --- docs/source/Tutorial_Algorithms.rst | 6 +- docs/source/XML_reference.rst | 4 +- docs/source/app_msg.rst | 3 + docs/source/app_s4u.rst | 28 ++++-- .../platform-profile/platform-profile.py | 6 +- src/bindings/python/simgrid_python.cpp | 96 ++++++++++++++++++- 6 files changed, 121 insertions(+), 22 deletions(-) diff --git a/docs/source/Tutorial_Algorithms.rst b/docs/source/Tutorial_Algorithms.rst index ab0cb3590d..3e3498194e 100644 --- a/docs/source/Tutorial_Algorithms.rst +++ b/docs/source/Tutorial_Algorithms.rst @@ -819,15 +819,11 @@ Lab 4: What-if analysis * Change the platform characteristics during the simulation. * Explore other communication patterns. -.. todo:: - - Some of the required functions are not implemented in Python yet. You can detect that if the method name is not a link to the documentation. - Computational speed ................... Attach a profile to your hosts, so that their computational speed automatically vary over time, modeling an external load on these machines. -This can be done with :cpp:func:`simgrid::s4u::Host::set_speed_profile` (C++) or :py:func:`simgrid.Host.set_speed_profile` (python). +This can be done with :cpp:func:`simgrid::s4u::Host::set_speed_profile` (C++) or :py:func:`simgrid.Host.set_speed_profile` (Python). Make it so that one of the hosts get really really slow, and observe how your whole application performance decreases. This is because one slow host slows down the whole process. Instead of a round-robin dispatch push, diff --git a/docs/source/XML_reference.rst b/docs/source/XML_reference.rst index 9435ecfb9c..1060796fd8 100644 --- a/docs/source/XML_reference.rst +++ b/docs/source/XML_reference.rst @@ -324,8 +324,8 @@ hyperlinks in an `hypergraph `_. 8.0 60000000 LOOPAFTER 12.0 - - At time t = 4, the bandwidth is of 40 MBps. - - At time t = 8, it raises to 60MBps. + - At time t = 4, the bandwidth is of 40 Mb/s. + - At time t = 8, it raises to 60 Mb/s. - At time t = 24, it drops at 40 MBps again. If your profile does not contain any LOOPAFTER line, then it will diff --git a/docs/source/app_msg.rst b/docs/source/app_msg.rst index d3dc33e474..ebfc632cca 100644 --- a/docs/source/app_msg.rst +++ b/docs/source/app_msg.rst @@ -359,6 +359,7 @@ Package org.simgrid.msg Class org.simgrid.msg.As Class org.simgrid.msg.Comm + Class org.simgrid.msg.File Class org.simgrid.msg.Host Class org.simgrid.msg.HostFailureException Class org.simgrid.msg.HostNotFoundException @@ -370,6 +371,8 @@ Package org.simgrid.msg Class org.simgrid.msg.ProcessKilledError Class org.simgrid.msg.ProcessNotFoundException Class org.simgrid.msg.Semaphore + Class org.simgrid.msg.Storage + Class org.simgrid.msg.StorageNotFoundException Class org.simgrid.msg.Task Class org.simgrid.msg.TaskCancelledException Class org.simgrid.msg.TimeoutException diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index c961b65caf..ee3d74b2d8 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -1324,6 +1324,7 @@ Querying info .. autoattribute:: simgrid.Host.load .. autoattribute:: simgrid.Host.pstate .. autoattribute:: simgrid.Host.speed + .. autoattribute:: simgrid.Host.available_speed .. group-tab:: C @@ -1402,14 +1403,11 @@ DVFS .. doxygenfunction:: simgrid::s4u::Host::get_pstate_count() const .. doxygenfunction:: simgrid::s4u::Host::get_pstate_speed(unsigned long pstate_index) const .. doxygenfunction:: simgrid::s4u::Host::set_pstate(unsigned long pstate_index) - .. doxygenfunction:: simgrid::s4u::Host::set_speed_profile(kernel::profile::Profile *p) - .. doxygenfunction:: simgrid::s4u::Host::set_state_profile(kernel::profile::Profile *p) .. group-tab:: Python .. automethod:: simgrid.Host.get_pstate_count .. automethod:: simgrid.Host.get_pstate_speed - .. automethod:: simgrid.Host.set_speed_profile .. group-tab:: C @@ -1419,6 +1417,21 @@ DVFS .. doxygenfunction:: sg_host_get_pstate_speed(const_sg_host_t host, unsigned long pstate_index) .. doxygenfunction:: sg_host_set_pstate(sg_host_t host, unsigned long pstate) +Dynamic profiles +---------------- + +.. tabs:: + + .. group-tab:: C++ + + .. doxygenfunction:: simgrid::s4u::Host::set_speed_profile(kernel::profile::Profile *p) + .. doxygenfunction:: simgrid::s4u::Host::set_state_profile(kernel::profile::Profile *p) + + .. group-tab:: Python + + .. automethod:: simgrid.Host.set_speed_profile + .. automethod:: simgrid.Host.set_state_profile + Execution --------- @@ -1654,6 +1667,12 @@ See :ref:`howto_churn` for more details. .. doxygenfunction:: simgrid::s4u::Link::set_latency_profile(kernel::profile::Profile *profile) .. doxygenfunction:: simgrid::s4u::Link::set_state_profile(kernel::profile::Profile *profile) + .. group-tab:: Python + + .. automethod:: simgrid.Link.set_bandwidth_profile + .. automethod:: simgrid.Link.set_latency_profile + .. automethod:: simgrid.Link.set_state_profile + WIFI links ---------- @@ -2497,9 +2516,6 @@ Locking .. doxygentypedef:: sg_bar_t .. doxygentypedef:: const_sg_bar_t - .. cpp:type:: const s4u_Barrier* const_sg_bar_t - - Pointer to a constant barrier object. .. doxygenfunction:: sg_barrier_init(unsigned int count) .. doxygenfunction:: sg_barrier_destroy(const_sg_bar_t bar) diff --git a/examples/python/platform-profile/platform-profile.py b/examples/python/platform-profile/platform-profile.py index 399fde7299..5c1cd20440 100644 --- a/examples/python/platform-profile/platform-profile.py +++ b/examples/python/platform-profile/platform-profile.py @@ -38,10 +38,8 @@ if __name__ == '__main__': # 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.set_speed_profile(""" -0 1.0 -2 0.5 -""", 2) + lili.set_speed_profile("""0 1.0 +2 0.5""", 2) lili.seal() # Add a watcher of the changes diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index c423bf7eec..5d990334f8 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -269,11 +269,43 @@ PYBIND11_MODULE(simgrid, m) h->route_to(to, *list, &bw); return make_tuple(list, bw); }, - "Retrieves the list of links and the bandwidth between two hosts") - .def("set_speed_profile", - [](Host* h, const std::string& profile, double period) { - h->set_speed_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); - }) + "Retrieves the list of links and the bandwidth between two hosts.") + .def( + "set_speed_profile", + [](Host* h, const std::string& profile, double period) { + h->set_speed_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); + }, + py::call_guard(), + "Specify a profile modeling the external load according to an exhaustive list. " + "Each line of the profile describes timed events as ``date ratio``. " + "For example, the following content describes an host which computational speed is initially 1 (i.e, 100%) " + "and then halved after 42 seconds:\n\n" + ".. code-block:: python\n\n" + " \"\"\"\n" + " 0 1.0\n" + " 42 0.5\n" + " \"\"\"\n\n" + ".. warning:: Don't get fooled: bandwidth and latency profiles of links contain absolute values," + " while speed profiles of hosts contain ratios.\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( + "set_state_profile", + [](Host* h, const std::string& profile, double period) { + h->set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); + }, + py::call_guard(), + "Specify a profile modeling the churn. " + "Each line of the profile describes timed events as ``date boolean``, where the boolean (0 or 1) tells " + "whether the host is on. " + "For example, the following content describes a link which turns off at t=1 and back on at t=2:\n\n" + ".. code-block:: python\n\n" + " \"\"\"\n" + " 1.0 0\n" + " 2.0 1\n" + " \"\"\"\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") @@ -363,6 +395,60 @@ PYBIND11_MODULE(simgrid, m) py::call_guard(), "Set the latency as a float (in seconds).") .def("set_bandwidth", &simgrid::s4u::Link::set_bandwidth, py::call_guard(), "Set the bandwidth (in byte per second).") + .def( + "set_bandwidth_profile", + [](simgrid::s4u::Link* l, const std::string& profile, double period) { + l->set_bandwidth_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); + }, + py::call_guard(), + "Specify a profile modeling the external load according to an exhaustive list. " + "Each line of the profile describes timed events as ``date bandwidth`` (in bytes per second). " + "For example, the following content describes a link which bandwidth changes to 40 Mb/s at t=4, and to 6 " + "Mb/s at t=8:\n\n" + ".. code-block:: python\n\n" + " \"\"\"\n" + " 4.0 40000000\n" + " 8.0 60000000\n" + " \"\"\"\n\n" + ".. warning:: Don't get fooled: bandwidth and latency profiles of links contain absolute values," + " while speed profiles of hosts contain ratios.\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( + "set_latency_profile", + [](simgrid::s4u::Link* l, const std::string& profile, double period) { + l->set_latency_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); + }, + py::call_guard(), + "Specify a profile modeling the external load according to an exhaustive list. " + "Each line of the profile describes timed events as ``date latency`` (in seconds). " + "For example, the following content describes a link which latency changes to 1ms (0.001s) at t=1, and to 2s " + "at t=2:\n\n" + ".. code-block:: python\n\n" + " \"\"\"\n" + " 1.0 0.001\n" + " 2.0 2\n" + " \"\"\"\n\n" + ".. warning:: Don't get fooled: bandwidth and latency profiles of links contain absolute values," + " while speed profiles of hosts contain ratios.\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( + "set_state_profile", + [](simgrid::s4u::Link* l, const std::string& profile, double period) { + l->set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period)); + }, + "Specify a profile modeling the churn. " + "Each line of the profile describes timed events as ``date boolean``, where the boolean (0 or 1) tells " + "whether the link is on. " + "For example, the following content describes a link which turns off at t=1 and back on at t=2:\n\n" + ".. code-block:: python\n\n" + " \"\"\"\n" + " 1.0 0\n" + " 2.0 1\n" + " \"\"\"\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("turn_on", &simgrid::s4u::Link::turn_on, py::call_guard(), "Turns the link on.") .def("turn_off", &simgrid::s4u::Link::turn_off, py::call_guard(), "Turns the link off.") -- 2.20.1