Graph

class eagerx.core.graph.Graph(state)[source]

The Graph API allows users to form a graph of connected nodes and objects.

add(entities)[source]

Add nodes/objects to the graph.

Parameters:

entities (Union[NodeSpec, ResetNodeSpec, ObjectSpec, EngineSpec, List[Union[NodeSpec, ResetNodeSpec, ObjectSpec, EngineSpec]]]) – Nodes/objects to add.

Return type:

None

add_component(entry=None, action=None, observation=None)[source]

Selects an available component entry (e.g. input, output, etc…) that was not already selected.

Parameters:
  • entry (Optional[SpecView]) – Selects the entry, so that it can be connected.

  • action (Optional[str]) – Adds a disconnected action entry.

  • observation (Optional[str]) – Adds a disconnected observation entry.

Return type:

None

connect(source=None, target=None, action=None, observation=None, window=None, delay=None, skip=None)[source]

Connect an action/source (i.e. node/object component) to an observation/target (i.e. node/object component).

Parameters:
  • source (Optional[SpecView]) – Compatible source types are outputs, sensors, and states.

  • target (Optional[SpecView]) – Compatible target types are inputs, actuators, targets, and feedthroughs.

  • action (Optional[str]) – Name of the action to connect (and add).

  • observation (Optional[str]) – Name of the observation to connect (and add).

  • window (Optional[int]) –

    A non-negative number that specifies the number of messages to pass to the node’s callback().

    • window = 1: Only the last received input message.

    • window = x > 1: The trailing last x received input messages.

    • window = 0: All input messages received since the last call to the node’s callback().

    Note

    With window = 0, the number of input messages may vary and can even be zero.

  • delay (Optional[float]) – A non-negative simulated delay (seconds). This delay is ignored if simulate_delays = True in the engine’s spec().

  • skip (Optional[bool]) – Skip the dependency on this input during the first call to the node’s callback(). May be necessary to ensure that the connected graph is directed and acyclic.

Return type:

None

classmethod create(nodes=None, objects=None)[source]

Create a new graph with nodes and objects.

Parameters:
Return type:

Graph

Returns:

The graph.

disconnect(source=None, target=None, action=None, observation=None, remove=False)[source]

Disconnects a source/action from a target/observation.

Parameters:
  • source (Optional[SpecView]) – Compatible source types are outputs, sensors, and states.

  • target (Optional[SpecView]) – Compatible target types are inputs, actuators, targets, and feedthroughs.

  • action (Optional[str]) – Name of the action to connect (and add).

  • observation (Optional[str]) – Name of the observation to connect (and add).

  • remove (bool) – Flag to also remove observations/actions if they are left disconnected after the entry was disconnected. Actions are only removed if they are completely disconnected.

Return type:

None

get(entry=None, action=None, observation=None, parameter=None)[source]

Fetches the parameters of a node/object/action/observation.

Parameters:
  • entry (Union[SpecView, EntitySpec, None]) – The entry whose parameters are fetched.

  • action (Optional[str]) – Action name whose parameters are fetched.

  • observation (Optional[str]) – observation name whose parameters are fetched.

  • parameter (Optional[str]) – If only a single parameter needs to be fetched.

Return type:

Any

Returns:

Parameters

get_spec(name)[source]

Get Spec from the graph

Parameters:

name (str) – Name

Return type:

EntitySpec

Returns:

The specification of the entity.

gui(interactive=True, resolution=None, filename=None)[source]

Opens a graphical user interface of the graph.

Note

Requires eagerx-gui:

pip3 install eagerx-gui
Parameters:
  • interactive (Optional[bool]) – If True, an interactive application is launched. Otherwise, an RGB render of the GUI is returned. This could be useful when using a headless machine.

  • resolution (Optional[List[int]]) – Specifies the resolution of the returned render when interactive is False. If interactive is True, this argument is ignored.

  • filename (Optional[str]) – If provided, the GUI is rendered to an svg file with this name. If interactive is True, this argument is ignored.

Return type:

Optional[ndarray]

Returns:

RGB render of the GUI if interactive is False.

is_valid(plot=True)[source]

Checks the validity of the graph.

Parameters:

plot – Flag to plot the graph. Can be helpful to identify cycles in the graph that break the required acyclic property.

Return type:

bool

Returns:

flag that specifies the validity of the graph.

classmethod load(file)[source]

Loads the graph state.

The state is loaded in .yaml format and contains the state of every added node, object, action, and observation and the connections between them.

Parameters:

file (str) – A string giving the name (and the file if the file isn’t in the current working directory).

reload()[source]

Reloads (ie imports) all entities in the graph.

remove(names, remove=False)[source]

Removes nodes/objects from the graph.

  • First, all associated connections are disconnected.

  • Then, removes the node/object.

Parameters:
  • names (Union[str, EntitySpec, List[Union[str, EntitySpec]]]) – Either the name or spec of the node/object that is to be removed.

  • remove (bool) – Flag to also remove observations/actions if they are left disconnected after the node/object was removed. Actions are only removed if they are completely disconnected.

Return type:

List

Returns:

list of disconnected connections.

remove_component(entry=None, action=None, observation=None, remove=False)[source]

Deselects a component entry (e.g. input, output, etc…) that was selected.

  • First, all associated connections are disconnected.

  • Then, deselects the component entry. For feedthroughs, it will also remove the corresponding output entry.

Parameters:
  • entry (Optional[SpecView]) – Deselects the entry.

  • action (Optional[str]) – Removes an action entry.

  • observation (Optional[str]) – Removes an observation entry

  • remove (bool) – Flag to also remove observations/actions if they are left disconnected after the entry was removed. Actions are only removed if they are completely disconnected.

Return type:

None

rename(new, action=None, observation=None)[source]

Renames an action/observation.

Parameters:
  • new (str) – New name.

  • action (Optional[str]) – Old action name.

  • observation (Optional[str]) – Old observation name.

Return type:

None

render(source, rate, processor=None, window=None, delay=None, skip=None, render_cls=None, process=0, encoding='bgr', **kwargs)[source]

Visualize rgb images produced by a node/sensor in the graph. The rgb images must be of dtype=uint8 and shape=(height, width, 3).

Parameters:
  • source (SpecView) – Compatible source types are outputs and sensors.

  • rate (float) – The rate (Hz) at which to render the images.

  • processor (Optional[ProcessorSpec]) – Processes the received message before passing it to the target node’s callback().

  • window (Optional[int]) –

    A non-negative number that specifies the number of messages to pass to the node’s callback().

    • window = 1: Only the last received input message.

    • window = x > 1: The trailing last x received input messages.

    • window = 0: All input messages received since the last call to the node’s callback().

    Note

    With window = 0, the number of input messages may vary and can even be zero.

  • delay (Optional[float]) – A non-negative simulated delay (seconds). This delay is ignored if simulate_delays = True in the engine’s spec().

  • skip (Optional[bool]) – Skip the dependency on this input during the first call to the node’s callback(). May be necessary to ensure that the connected graph is directed and acyclic.

  • render_cls (Optional[Type[Node]]) – The Node of the render node. By default, it uses the standard RenderNode. In Google colab, the ColabRender class is used.

  • process (int) – Process in which the render node is launched. See process for all options.

  • encoding (str) – The encoding (bgr or rgb) of the render source.

  • kwargs – Optional arguments required by the render node.

save(file)[source]

Saves the graph state.

The state is saved in .yaml format and contains the state of every added node, object, action, and observation and the connections between them.

Parameters:

file (str) – A string giving the name (and the file if the file isn’t in the current working directory).

Return type:

None

set(mapping, entry=None, action=None, observation=None, parameter=None)[source]

Sets the parameters of a node/object/action/observation.

Parameters:
  • mapping (Any) – Either a mapping with key = parameter, or a single value that corresponds to the optional parameter argument.

  • entry (Optional[SpecView]) – The entry whose parameters are mutated.

  • action (Optional[str]) – Action name whose parameters are mutated.

  • observation (Optional[str]) – observation name whose parameters are mutated.

  • parameter (Optional[str]) – If only a single value needs to be set. See documentation for mapping.

Return type:

None