+ "The peak computing speed in flops/s at the current pstate, NOT taking the external load into account. "
+ "This is the max potential speed (read-only property).")
+ .def_property_readonly("available_speed", &Host::get_available_speed,
+ "Get the available speed ratio, between 0 and 1.\n"
+ "This accounts for external load (see :py:func:`set_speed_profile() "
+ "<simgrid.Host.set_speed_profile>`) (read-only property).")
+ .def_static(
+ "on_creation_cb",
+ [](py::object cb) {
+ cb.inc_ref(); // keep alive after return
+ const py::gil_scoped_release gil_release;
+ Host::on_creation_cb([cb_p = cb.ptr()](Host& h) {
+ const py::gil_scoped_acquire py_context; // need a new context for callback
+ try {
+ const auto fun = py::reinterpret_borrow<py::function>(cb_p);
+ fun(&h);
+ } catch (const py::error_already_set& e) {
+ xbt_die("Error while executing the on_creation lambda : %s", e.what());
+ }
+ });
+ },
+ "")
+ .def(
+ "__repr__", [](const Host* h) { return "Host(" + h->get_name() + ")"; },
+ "Textual representation of the Host.");
+
+ m.def("sg_host_load_plugin_init", [host]() {
+ sg_host_load_plugin_init();
+
+ static_cast<pybind11::class_<simgrid::s4u::Host, std::unique_ptr<simgrid::s4u::Host, pybind11::nodelete>>>(host)
+ .def(
+ "reset_load", [](const Host* h) { sg_host_load_reset(h); }, py::call_guard<py::gil_scoped_release>(),
+ "Reset counters of the host load plugin for this host.")
+ .def_property_readonly(
+ "current_load", [](const Host* h) { return sg_host_get_current_load(h); }, "Current load of the host.")
+ .def_property_readonly(
+ "avg_load", [](const Host* h) { return sg_host_get_avg_load(h); }, "Average load of the host.")
+ .def_property_readonly(
+ "idle_time", [](const Host* h) { return sg_host_get_idle_time(h); }, "Idle time of the host")
+ .def_property_readonly(
+ "total_idle_time", [](const Host* h) { return sg_host_get_total_idle_time(h); },
+ "Total idle time of the host.")
+ .def_property_readonly(
+ "computed_flops", [](const Host* h) { return sg_host_get_computed_flops(h); },
+ "Computed flops of the host.");
+ });
+
+ py::enum_<simgrid::s4u::Host::SharingPolicy>(host, "SharingPolicy")
+ .value("NONLINEAR", simgrid::s4u::Host::SharingPolicy::NONLINEAR)
+ .value("LINEAR", simgrid::s4u::Host::SharingPolicy::LINEAR)
+ .export_values();
+
+ /* Class Disk */
+ py::class_<simgrid::s4u::Disk, std::unique_ptr<simgrid::s4u::Disk, py::nodelete>> disk(
+ m, "Disk", "Simulated disk. See the C++ documentation for details.");
+ disk.def("read", py::overload_cast<sg_size_t, double>(&simgrid::s4u::Disk::read, py::const_),
+ py::call_guard<py::gil_scoped_release>(), "Read data from disk", py::arg("size"), py::arg("priority") = 1)
+ .def("write", py::overload_cast<sg_size_t, double>(&simgrid::s4u::Disk::write, py::const_),
+ py::call_guard<py::gil_scoped_release>(), "Write data in disk", py::arg("size"), py::arg("priority") = 1)
+ .def("read_async", &simgrid::s4u::Disk::read_async, py::call_guard<py::gil_scoped_release>(),
+ "Non-blocking read data from disk")
+ .def("write_async", &simgrid::s4u::Disk::write_async, py::call_guard<py::gil_scoped_release>(),
+ "Non-blocking write data in disk")
+ .def("set_sharing_policy", &simgrid::s4u::Disk::set_sharing_policy, py::call_guard<py::gil_scoped_release>(),
+ "Set sharing policy for this disk", py::arg("op"), py::arg("policy"),
+ py::arg("cb") = simgrid::s4u::NonLinearResourceCb())
+ .def("seal", &simgrid::s4u::Disk::seal, py::call_guard<py::gil_scoped_release>(), "Seal this disk")
+ .def_property_readonly("name", &simgrid::s4u::Disk::get_name, "The name of this disk (read-only property).")
+ .def(
+ "__repr__", [](const Disk* d) { return "Disk(" + d->get_name() + ")"; },
+ "Textual representation of the Disk");
+ py::enum_<simgrid::s4u::Disk::SharingPolicy>(disk, "SharingPolicy")
+ .value("NONLINEAR", simgrid::s4u::Disk::SharingPolicy::NONLINEAR)
+ .value("LINEAR", simgrid::s4u::Disk::SharingPolicy::LINEAR)
+ .export_values();
+ py::enum_<simgrid::s4u::Disk::Operation>(disk, "Operation")
+ .value("READ", simgrid::s4u::Disk::Operation::READ)
+ .value("WRITE", simgrid::s4u::Disk::Operation::WRITE)
+ .value("READWRITE", simgrid::s4u::Disk::Operation::READWRITE)
+ .export_values();
+
+ /* Class NetPoint */
+ py::class_<simgrid::kernel::routing::NetPoint, std::unique_ptr<simgrid::kernel::routing::NetPoint, py::nodelete>>
+ netpoint(m, "NetPoint", "NetPoint object");
+
+ /* Class Link */
+ py::class_<Link, std::unique_ptr<Link, py::nodelete>> link(m, "Link",
+ "Network link. See the C++ documentation for details.");
+ link.def("set_latency", py::overload_cast<const std::string&>(&Link::set_latency),
+ py::call_guard<py::gil_scoped_release>(),
+ "Set the latency as a string. Accepts values with units, such as ‘1s’ or ‘7ms’.\nFull list of accepted "
+ "units: w (week), d (day), h, s, ms, us, ns, ps.")
+ .def("set_latency", py::overload_cast<double>(&Link::set_latency), py::call_guard<py::gil_scoped_release>(),
+ "Set the latency as a float (in seconds).")
+ .def("set_bandwidth", &Link::set_bandwidth, py::call_guard<py::gil_scoped_release>(),
+ "Set the bandwidth (in byte per second).")
+ .def(
+ "set_bandwidth_profile",
+ [](Link* l, const std::string& profile, double period) {
+ l->set_bandwidth_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period));
+ },
+ py::call_guard<py::gil_scoped_release>(),
+ "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",
+ [](Link* l, const std::string& profile, double period) {
+ l->set_latency_profile(simgrid::kernel::profile::ProfileBuilder::from_string("", profile, period));
+ },
+ py::call_guard<py::gil_scoped_release>(),
+ "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",
+ [](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", &Link::turn_on, py::call_guard<py::gil_scoped_release>(), "Turns the link on.")
+ .def("turn_off", &Link::turn_off, py::call_guard<py::gil_scoped_release>(), "Turns the link off.")
+ .def("is_on", &Link::is_on, "Check whether the link is on.")
+
+ .def("set_sharing_policy", &Link::set_sharing_policy, py::call_guard<py::gil_scoped_release>(),
+ "Set sharing policy for this link")
+ .def("set_concurrency_limit", &Link::set_concurrency_limit, py::call_guard<py::gil_scoped_release>(),
+ "Set concurrency limit for this link")
+ .def("set_host_wifi_rate", &Link::set_host_wifi_rate, py::call_guard<py::gil_scoped_release>(),
+ "Set level of communication speed of given host on this Wi-Fi link")
+ .def_static("by_name", &Link::by_name, "Retrieves a Link from its name, or dies")
+ .def("seal", &Link::seal, py::call_guard<py::gil_scoped_release>(), "Seal this link")
+ .def_property_readonly("name", &Link::get_name, "The name of this link")
+ .def_property_readonly("bandwidth", &Link::get_bandwidth,
+ "The bandwidth (in bytes per second) (read-only property).")
+ .def_property_readonly("latency", &Link::get_latency, "The latency (in seconds) (read-only property).")
+ .def(
+ "__repr__", [](const Link* l) { return "Link(" + l->get_name() + ")"; },
+ "Textual representation of the Link");
+ py::enum_<Link::SharingPolicy>(link, "SharingPolicy")
+ .value("NONLINEAR", Link::SharingPolicy::NONLINEAR)
+ .value("WIFI", Link::SharingPolicy::WIFI)
+ .value("SPLITDUPLEX", Link::SharingPolicy::SPLITDUPLEX)
+ .value("SHARED", Link::SharingPolicy::SHARED)
+ .value("FATPIPE", Link::SharingPolicy::FATPIPE)
+ .export_values();
+
+ /* Class LinkInRoute */
+ py::class_<simgrid::s4u::LinkInRoute> linkinroute(m, "LinkInRoute", "Abstraction to add link in routes");
+ linkinroute.def(py::init<const Link*>());
+ linkinroute.def(py::init<const Link*, simgrid::s4u::LinkInRoute::Direction>());
+ py::enum_<simgrid::s4u::LinkInRoute::Direction>(linkinroute, "Direction")
+ .value("UP", simgrid::s4u::LinkInRoute::Direction::UP)
+ .value("DOWN", simgrid::s4u::LinkInRoute::Direction::DOWN)
+ .value("NONE", simgrid::s4u::LinkInRoute::Direction::NONE)
+ .export_values();
+
+ /* Class Split-Duplex Link */
+ py::class_<simgrid::s4u::SplitDuplexLink, Link, std::unique_ptr<simgrid::s4u::SplitDuplexLink, py::nodelete>>(
+ m, "SplitDuplexLink", "Network split-duplex link")
+ .def_property_readonly("link_up", &simgrid::s4u::SplitDuplexLink::get_link_up, "Get link direction up")
+ .def_property_readonly("link_down", &simgrid::s4u::SplitDuplexLink::get_link_down, "Get link direction down");