Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import sys
import json
import math
import pickle
import pprint

import netaddr
from rich.console import Console
Expand Down Expand Up @@ -457,17 +457,15 @@ def __str__(self):
Returns:
str: A string representation of an :py:class:`base_objects.Interfaces`.
"""
ret = "[\n"
ret = []
for interface in self.interfaces:
new_int = dict(interface)
new_int["address"] = str(new_int["address"])
new_int["netmask"] = str(new_int["netmask"])
new_int["network"] = str(new_int["network"])
new_int["switch"] = new_int["switch"].name
ret += pprint.pformat(new_int)
ret += ",\n"
ret += "]"
return ret
ret.append(new_int)
return json.dumps(ret)


class VMEndpoint:
Expand Down
2 changes: 1 addition & 1 deletion src/firewheel_repo_base/common/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run(self):
shell = True

# Run the program
run = Popen( # noqa: DUO116
run = Popen(
arguments,
stdout=PIPE,
stderr=PIPE,
Expand Down
9 changes: 9 additions & 0 deletions src/firewheel_repo_base/misc/print_schedule/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: misc.print_schedule
attributes:
depends:
- graph
- schedules_ready
provides: []
model_components:
depends: []
plugin: plugin.py
27 changes: 27 additions & 0 deletions src/firewheel_repo_base/misc/print_schedule/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _misc.print_schedule_mc:

###################
misc.print_schedule
###################

This MC outputs a JSON representation of the entire experiment's :ref:`vm-resource-schedule`.
If a filename is passed into the Plugin, then the JSON is written to a file; otherwise, it will print the schedule to ``stdout``.
This JSON is useful for analyzing the expected experiment schedule and reviewing inputs to various involve VM resources.
This output does **NOT** include associated VM resource scripts nor binary files to reduce file size.

This MC can be placed in multiple locations of the experiment pipeline so that users can see different views of how the experiment schedule is evolving.

**Attribute Depends:**
* ``graph``

******
Plugin
******

.. automodule:: misc.print_schedule_plugin
:members:
:undoc-members:
:special-members:
:private-members:
:show-inheritance:
:exclude-members: __dict__,__weakref__,__module__
63 changes: 63 additions & 0 deletions src/firewheel_repo_base/misc/print_schedule/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import json
from pathlib import Path

import rich

from firewheel.control.experiment_graph import AbstractPlugin


class PrintSchedule(AbstractPlugin):
"""
Print out all VM Resource Schedules in JSON format.
This Plugin optionally takes in a filename which will be used to write output.
If no filename is provided, the schedule will be printed to ``stdout``.
"""

def _generate_schedule(self):
"""
Get the ``vm_resource_schedule`` for all vertices in the graph and effectively
acquire the schedule attributes.

Returns:
dict: The sorted dictionary of schedule entries.
"""

full_schedule = {}
for vert in self.g.get_vertices():
vm_schedule = vert.__dict__.get("vm_resource_schedule", None)

if vm_schedule is None:
continue

# Iterate over schedule
for entry in vm_schedule.get_schedule():
full_schedule[entry.start_time] = full_schedule.get(entry.start_time, [])
full_schedule[entry.start_time].append({
"name": vert.name,
"executable": entry.executable,
"arguments": entry.arguments,
"data": entry.data,
"pause": entry.pause,
})

return dict(sorted(full_schedule.items()))

def run(self, output_file=""):
"""
Identifies whether the output should be printed or added to a file.
If a output file is identified, the schedule output is produced in JSON format.

Args:
output_file (str, optional): The name/path to a file for the JSON output.
Defaults to ``""``.
"""
schedule = self._generate_schedule()
if output_file:
with open(output_file, "w", encoding="UTF-8") as out:
json.dump(schedule, out)
rich.print(
"[b yellow]Output experiment schedule to: "
f"[magenta]{Path(output_file).absolute()!s}"
)
else:
rich.print(schedule)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ passenv =

[testenv:ruff]
basepython = python3
deps = ruff==0.7.1
deps = ruff==0.12.9
commands =
ruff check {posargs}

Expand Down Expand Up @@ -98,4 +98,4 @@ format = %(cyan)s%(path)s%(reset)s:%(bold)s%(yellow)s%(row)d%(reset)s:%(bold)s%(

# Options for pydoclint
style = google
arg-type-hints-in-signature = False
arg-type-hints-in-signature = False