Skip to content

phyelds.vm

phyelds.vm

Engine interface: how to implement an aggregate computing engine.

NodeContext

Bases: ABC

Abstract base class for the node context. This class should be implemented by the user.

__init__(node_id, sensors=None, outputs=None)

Initialize the node context with the node id and sensors.

Parameters:

Name Type Description Default
node_id int

The id of the node.

required
sensors dict[str, any]

The sensors of the node.

None

sense(sensor_name)

Get the value of the sensor.

Parameters:

Name Type Description Default
sensor_name str

The name of the sensor.

required

Returns:

Type Description
any

The value of the sensor.

store(output_name, value)

Store the value of the output.

Parameters:

Name Type Description Default
output_name str

The name of the output.

required
value any

The value to store.

required

position()

Get the position of the node.

Returns:

Type Description
any

The position of the node.

time()

Get the current time of the node.

Returns:

Type Description
float

The current time of the node.

EngineState dataclass

Inner state of the engine used to process aggregate computation.

Engine

Bases: ABC

Abstract base class for the engine. This class should be implemented by the user.

setup(node_context, messages, state=None)

Setup the engine with the current context.

Parameters:

Name Type Description Default
node_context NodeContext

the current context of the engine.

required
messages dict[int, dict[str, any]]

The messages to send.

required
state

The state of the engine.

None

enter(name)

Enter a new context.

Parameters:

Name Type Description Default
name str

The name of the context.

required

exit()

Exit the current context.

current_path()

Get the current path of the engine.

Returns:

Type Description
list[str]

The current path.

write_state(value, stack)

Write the state of the engine.

Parameters:

Name Type Description Default
value any

The value to write.

required
stack list[str]

The stack of the engine.

required

read_state(stack)

Read the state of the engine.

Parameters:

Name Type Description Default
stack list[str]

The stack of the engine.

required

Returns:

Type Description
any

The value of the state.

state_trace()

Get the state trace of the engine.

Returns:

Type Description
dict[str, any]

The state trace.

forget(_self_path)

Forget the value store in the engine.

Parameters:

Name Type Description Default
_self_path
required

Returns:

Type Description

send(data)

Send data to the engine.

Parameters:

Name Type Description Default
data any

The data to send.

required

aligned()

Get the aligned ids.

Returns:

Type Description
list[int]

The aligned ids.

aligned_values(path)

Get the aligned values.

Parameters:

Name Type Description Default
path list[str]

The path of the values.

required

Returns:

Type Description
dict[int, any]

The aligned values.

cooldown()

Cooldown the engine.

Returns:

Type Description
dict[str, Any]