X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c068a4c3f394aff9a0c991e0945313c72d78a51a..ad6c13e59372de15e361f15bbb7f5861c6873d4d:/src/bindings/python/simgrid_python.cpp diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 7b5efdb41e..c423bf7eec 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2018-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2018-2022. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -22,6 +22,7 @@ #pragma GCC diagnostic pop #endif +#include "simgrid/kernel/ProfileBuilder.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include "src/kernel/context/Context.hpp" #include @@ -86,7 +87,9 @@ PYBIND11_MODULE(simgrid, m) static py::object pyForcefulKillEx(py::register_exception(m, "ActorKilled")); /* this_actor namespace */ - m.def_submodule("this_actor", "Bindings of the s4u::this_actor namespace.") + m.def_submodule("this_actor", "Bindings of the s4u::this_actor namespace. See the C++ documentation for details.") + .def( + "debug", [](const char* s) { XBT_DEBUG("%s", s); }, "Display a logging message of 'debug' priority.") .def( "info", [](const char* s) { XBT_INFO("%s", s); }, "Display a logging message of 'info' priority.") .def( @@ -123,23 +126,41 @@ PYBIND11_MODULE(simgrid, m) } }); }, - py::call_guard(), ""); + py::call_guard(), "") + .def("get_pid", &simgrid::s4u::this_actor::get_pid, "Retrieves PID of the current actor") + .def("get_ppid", &simgrid::s4u::this_actor::get_ppid, + "Retrieves PPID of the current actor (i.e., the PID of its parent)."); /* Class Engine */ py::class_(m, "Engine", "Simulation Engine") .def(py::init([](std::vector args) { - auto argc = static_cast(args.size()); - std::vector argv(args.size() + 1); // argv[argc] is nullptr - std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); }); - // Currently this can be dangling, we should wrap this somehow. - return new simgrid::s4u::Engine(&argc, argv.data()); - })) + auto argc = static_cast(args.size()); + std::vector argv(args.size() + 1); // argv[argc] is nullptr + std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); }); + // Currently this can be dangling, we should wrap this somehow. + 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, "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("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") + .def("run", &Engine::run, py::call_guard(), "Run the simulation until its end") + .def("run_until", py::overload_cast(&Engine::run_until, py::const_), + py::call_guard(), "Run the simulation until the given date", + py::arg("max_date") = -1) .def( "register_actor", [](Engine* e, const std::string& name, py::object fun_or_class) { @@ -167,8 +188,8 @@ PYBIND11_MODULE(simgrid, m) "Registers the main function of an actor"); /* Class Netzone */ - py::class_> netzone(m, "NetZone", - "Networking Zones"); + py::class_> netzone( + m, "NetZone", "Networking Zones. See the C++ documentation for details."); netzone.def_static("create_full_zone", &simgrid::s4u::create_full_zone, "Creates a zone of type FullZone") .def_static("create_torus_zone", &simgrid::s4u::create_torus_zone, "Creates a cluster of type Torus") .def_static("create_fatTree_zone", &simgrid::s4u::create_fatTree_zone, "Creates a cluster of type Fat-Tree") @@ -237,8 +258,22 @@ PYBIND11_MODULE(simgrid, m) const std::pair&, unsigned int>()); /* Class Host */ - py::class_> host(m, "Host", "Simulated host"); + py::class_> host( + m, "Host", "Simulated host. See the C++ documentation for details."); host.def("by_name", &Host::by_name, "Retrieves a host from its name, or die") + .def( + "route_to", + [](simgrid::s4u::Host* h, simgrid::s4u::Host* to) { + auto* list = new std::vector(); + double bw = 0; + 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)); + }) .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") @@ -270,22 +305,29 @@ PYBIND11_MODULE(simgrid, m) return std::string(self->get_name().c_str()); // Convert from xbt::string because of MC }, "The name of this host") - .def_property_readonly( - "load", &Host::get_load, - "Returns the current computation load (in flops per second). This is the currently achieved speed.") + .def_property_readonly("load", &Host::get_load, + "Returns the current computation load (in flops per second), NOT taking the external load " + "into account. This is the currently achieved speed.") .def_property_readonly( "speed", &Host::get_speed, - "The peak computing speed in flops/s at the current pstate, taking the external load into account. " - "This is the max potential speed."); + "The peak computing speed in flops/s at the current pstate, NOT taking the external load into account. " + "This is the max potential speed.") + .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() `)."); py::enum_(host, "SharingPolicy") .value("NONLINEAR", simgrid::s4u::Host::SharingPolicy::NONLINEAR) .value("LINEAR", simgrid::s4u::Host::SharingPolicy::LINEAR) .export_values(); /* Class Disk */ - py::class_> disk(m, "Disk", "Simulated disk"); - disk.def("read", &simgrid::s4u::Disk::read, py::call_guard(), "Read data from disk") - .def("write", &simgrid::s4u::Disk::write, py::call_guard(), "Write data in disk") + py::class_> disk( + m, "Disk", "Simulated disk. See the C++ documentation for details."); + disk.def("read", py::overload_cast(&simgrid::s4u::Disk::read, py::const_), + py::call_guard(), "Read data from disk", py::arg("size"), py::arg("priority") = 1) + .def("write", py::overload_cast(&simgrid::s4u::Disk::write, py::const_), + py::call_guard(), "Write data in disk", py::arg("size"), py::arg("priority") = 1) .def("read_async", &simgrid::s4u::Disk::read_async, py::call_guard(), "Non-blocking read data from disk") .def("write_async", &simgrid::s4u::Disk::write_async, py::call_guard(), @@ -311,24 +353,38 @@ PYBIND11_MODULE(simgrid, m) netpoint(m, "NetPoint", "NetPoint object"); /* Class Link */ - py::class_> link(m, "Link", "Network link"); + py::class_> link( + m, "Link", "Network link. See the C++ documentation for details."); link.def("set_latency", py::overload_cast(&simgrid::s4u::Link::set_latency), - py::call_guard(), "Set the latency") + py::call_guard(), + "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(&simgrid::s4u::Link::set_latency), - py::call_guard(), "Set the latency") + 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("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.") + .def("is_on", &simgrid::s4u::Link::is_on, "Check whether the link is on.") + .def("set_sharing_policy", &simgrid::s4u::Link::set_sharing_policy, py::call_guard(), "Set sharing policy for this link") .def("set_concurrency_limit", &simgrid::s4u::Link::set_concurrency_limit, py::call_guard(), "Set concurrency limit for this link") .def("set_host_wifi_rate", &simgrid::s4u::Link::set_host_wifi_rate, py::call_guard(), "Set level of communication speed of given host on this Wi-Fi link") + .def("by_name", &simgrid::s4u::Link::by_name, "Retrieves a Link from its name, or dies") .def("seal", &simgrid::s4u::Link::seal, py::call_guard(), "Seal this link") .def_property_readonly( "name", [](const simgrid::s4u::Link* self) { return std::string(self->get_name().c_str()); // Convert from xbt::string because of MC }, - "The name of this link"); + "The name of this link") + .def_property_readonly("bandwidth", &simgrid::s4u::Link::get_bandwidth, "The bandwidth (in bytes per second)") + .def_property_readonly("latency", &simgrid::s4u::Link::get_latency, "The latency (in seconds)"); + py::enum_(link, "SharingPolicy") .value("NONLINEAR", simgrid::s4u::Link::SharingPolicy::NONLINEAR) .value("WIFI", simgrid::s4u::Link::SharingPolicy::WIFI) @@ -355,7 +411,8 @@ PYBIND11_MODULE(simgrid, m) .def("get_link_down", &simgrid::s4u::SplitDuplexLink::get_link_down, "Get link direction down"); /* Class Mailbox */ - py::class_>(m, "Mailbox", "Mailbox") + py::class_>( + m, "Mailbox", "Mailbox. See the C++ documentation for details.") .def( "__str__", [](const Mailbox* self) { return std::string("Mailbox(") + self->get_cname() + ")"; }, "Textual representation of the Mailbox`") @@ -409,7 +466,8 @@ PYBIND11_MODULE(simgrid, m) "Get python object after async communication in receiver side"); /* Class Comm */ - py::class_(m, "Comm", "Communication") + py::class_(m, "Comm", + "Communication. See the C++ documentation for details.") .def("test", &simgrid::s4u::Comm::test, py::call_guard(), "Test whether the communication is terminated.") .def("wait", &simgrid::s4u::Comm::wait, py::call_guard(), @@ -424,7 +482,7 @@ PYBIND11_MODULE(simgrid, m) "Block until the completion of any communication in the list and return the index of the terminated one."); /* Class Io */ - py::class_(m, "Io", "I/O activities") + py::class_(m, "Io", "I/O activities. See the C++ documentation for details.") .def("test", &simgrid::s4u::Io::test, py::call_guard(), "Test whether the I/O is terminated.") .def("wait", &simgrid::s4u::Io::wait, py::call_guard(), @@ -436,7 +494,7 @@ PYBIND11_MODULE(simgrid, m) "Block until the completion of any I/O in the list and return the index of the terminated one."); /* Class Exec */ - py::class_(m, "Exec", "Execution") + py::class_(m, "Exec", "Execution. See the C++ documentation for details.") .def_property_readonly( "remaining", [](simgrid::s4u::ExecPtr self) { @@ -464,7 +522,7 @@ PYBIND11_MODULE(simgrid, m) /* Class Actor */ py::class_(m, "Actor", "An actor is an independent stream of execution in your distributed " - "application") + "application. See the C++ documentation for details.") .def( "create", [](py::str name, Host* h, py::object fun, py::args args) { @@ -483,7 +541,7 @@ PYBIND11_MODULE(simgrid, m) } }); }, - py::call_guard(), "Create an actor from a function or an object.") + py::call_guard(), "Create an actor from a function or an object. See the :ref:`example `.") .def_property( "host", &Actor::get_host, [](Actor* a, Host* h) {