phyelds.simulator¶
phyelds.simulator
¶
A simple simulator for aggregate computing systems in phyelds. This simulator allows you to create nodes, set their positions and data, and define their neighborhoods. It also provides a way to schedule events and run the simulation.
Node
¶
Environment
¶
A class to represent the environment in which nodes exist. It manages the nodes and their neighborhoods. It also provides a way to set the neighborhood function.
add_data_for_all_nodes(data)
¶
Add data to all nodes in the environment
node_list()
¶
Return a list of all nodes in the environment
add_node(node)
¶
Add a node to the environment
remove_node(node_id)
¶
Remove a node from the environment
set_neighborhood_function(func)
¶
Set the function that determines neighborhoods
get_neighbors(node)
¶
Get neighbors for a node using the neighborhood function
no_neighbors(node, all_node)
staticmethod
¶
Default neighborhood function (no neighbors)
Event
¶
Monitor
¶
Simulator
¶
A class to represent the simulator for a simple aggregate computing system.
schedule_event(time_delta, action, *args, **kwargs)
¶
Schedule an event to occur after time_delta
run(until_time=None)
¶
Run the simulation until the specified time or until no more events
continue_run(until_time=None)
¶
Continue running the simulation until the specified time or until no more events
add_monitor(monitor)
¶
Add a monitor to the simulator
stop()
¶
Stop the simulation
cancel_event(event)
¶
Cancel a scheduled event
reset()
¶
Reset the simulator
create_node(position, data=None, node_id=None)
¶
Helper method to create and add a node to the environment
phyelds.simulator.deployments
¶
This module contains various functions to generate different types of node distributions in a simulation environment. These functions can be used to create specific patterns or random distributions of nodes for testing and simulation purposes.
grid_generation(simulator, width, height, spacing)
¶
Generate a grid of nodes in the simulator's environment.
deformed_lattice(simulator, width, height, spacing, deformation_factor)
¶
Generate a deformed lattice of nodes in the simulator's environment.
random_walk(simulator, num_steps, step_size)
¶
Perform a random walk and create nodes at each step.
random_in_circle(simulator, num_nodes, radius)
¶
Generate nodes randomly distributed within a circle.
phyelds.simulator.neighborhood
¶
Neighborhood functions for the phyelds simulator. A neighborhood function is simply a function that takes a node and a list of all nodes, and returns a list of neighbors.
phyelds.simulator.runner
¶
This module contains the event to run the aggregate program in the simulator
SimulatorNodeContext
¶
Bases: NodeContext, ABC
A class to represent the context of a node in the simulator. This class is used to pass the node's data and messages to the aggregate program.
aggregate_program_runner(simulator, time_delta, node, program, **kwargs)
¶
Run the program for a node.
schedule_program_for_all(simulator, start, frequency, program, **kwargs)
¶
Schedule the program for all nodes in the simulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulator
|
Simulator
|
The simulator to schedule the program for. |
required |
start
|
float
|
The time to start the program. |
required |
frequency
|
float
|
The frequency to run the program. |
required |
program
|
callable
|
The program to run. |
required |
phyelds.simulator.actions
¶
phyelds.simulator.effects
¶
This module contains the effects that can be applied to the simulation rendering.
Link
¶
A class to represent a link between two nodes. The link is represented as a tuple of two nodes. Note! Link(node1, node2) == Link(node2, node1)
Effect
¶
Bases: BaseModel, ABC
Abstract base class for effects.
apply(ax, environment)
abstractmethod
¶
Apply the effect to the matplotlib axis.
DrawEdges
¶
DrawNodes
¶
Bases: Effect
Draw nodes.
With color_from alone, node.data[color_from] is used as a matplotlib color.
With cmap too, it is read as a number and mapped onto that colormap between
vmin and vmax (by default, the finite values on screen); nodes whose value is
missing, infinite or not a number are drawn in missing_color.
apply(ax, environment)
¶
Draw nodes.
DrawValues
¶
RenderMode
¶
Bases: str, Enum
Enum for render modes.
RenderConfig
¶
validate_effect(v)
¶
Validate the effect type.
phyelds.simulator.render
¶
Render the nodes in the simulator's environment.
phyelds.simulator.exporter
¶
Exporter module for saving simulation metrics to CSV during simulation.
ExporterConfig
dataclass
¶
Configuration for CSV exporting of simulation metrics.
csv_exporter(simulator, time_delta, config, **kwargs)
¶
Exporter module for saving simulation metrics to CSV.
aggregate_values(values, precision, aggregator)
¶
Aggregates a list of values using the given method and rounds to the specified precision.
init_dataframe(config, file_path)
¶
Initializes an empty DataFrame with appropriate columns based on config.