Auxiliary Scripts

Here you can find a description of all the scripts that provide supporting functionality for the core elements. These auxiliary modules implement common tools and abstractions which are used in this type of nodes.

File

Python script to implement a file handler, which is responsible for writing files with data of the cognitive architecture. The files avaliable to write are:

  • Goodness: A file where several goodness statistics about an experiment are stored.

  • P-Nodes Sucess: A file that records wether a P-node’s activation has been successful or not.

  • Trials Sucess: A file that record de number of trials to ahieve a goal and whether it was successful or not.

  • P-Nodes Content: A file that saves the contents of the P-Nodes every 100 iterations.

  • Last Iteration P-Nodes Content: A file that saves the contents of the P-Nodes at the last iteration of an experiment.

  • Goals Content: A file that saves the contents of the Goals every 100 iterations.

  • Last Iteration Goals Content: A file that saves the contents of the Goals at the last iteration of an experiment.

  • Neighbors: File specific to track the subgoals created by effectance.

  • Neighbors Full: A file that saves the full neighbor tree at the end of an experiment.

The desired ouput files can be specified in the configuration file of the experiment.

class core.file.File(ident, file_name, node, **params)[source]

Bases: object

A MDB file.

close()[source]

Close de underlying file.

write()[source]

Method that writes the data in the file

write_episode(msg)[source]

Writes data related to an episode

write_header()[source]

Write the header of the file.

class core.file.FileDrivesPerceptions(ident, file_name, node, **params)[source]

Bases: File

A file where several drive evaluation statistics about an experiment are stored.

write()[source]

Write the drive evaluation and missions.

write_header()[source]

Write the header of the file.

class core.file.FileEpisodesDataset(**kwargs)[source]

Bases: File

A file that records the episodes published

close()[source]

Close de underlying file.

write()[source]

Method that writes the data in the file

write_episode(msg)[source]

Writes data related to an episode

class core.file.FileGoalsContent(ident, file_name, node, save_interval=100, **params)[source]

Bases: File

A file that saves the contents of the Goals at the end of an experiment.

create_goal_client(goal_name)[source]

Create client to request Goal’s space.

Parameters:

goal_name (str) – Name of the Goal.

finish_header(labels)[source]

Write Goals dimensions in the header of the file.

Parameters:

labels (list) – Dimensions of the Goal.

write()[source]

Writes Goals contents.

write_header()[source]

Write the header of the file.

class core.file.FileGoodness(ident, file_name, node, **params)[source]

Bases: File

A file where several goodness statistics about an experiment are stored.

write()[source]

Write statistics data.

write_header()[source]

Write the header of the file.

class core.file.FileLastIterationGoalsContent(ident, file_name, node, save_interval=100, **params)[source]

Bases: FileGoalsContent

A file that saves the contents of the Goals at the end of an experiment.

write()[source]

Writes Goals contents.

class core.file.FileLastIterationPNodesContent(ident, file_name, node, save_interval=100, **params)[source]

Bases: FilePNodesContent

A file that saves the contents of the P-nodes at the end of an experiment.

write()[source]

Writes P-Nodes contents

class core.file.FileNeighbors(ident, file_name, node, **params)[source]

Bases: File

A file that saves the neighbors of each node (Method specific to track the subgoals created by effectance).

write()[source]

Writes neighbors list.

write_header()[source]

Write the header of the file.

class core.file.FileNeighborsFull(ident, file_name, node, **params)[source]

Bases: File

A file that saves the full neighbor tree at the end of an experiment.

write()[source]

Writes neighbors list for each node.

write_header()[source]

Write the header of the file.

class core.file.FilePNodesContent(ident, file_name, node, save_interval=100, **params)[source]

Bases: File

A file that saves the contents of the P-nodes.

create_pnode_client(pnode_name)[source]

Create client to request P-Node’s space.

Parameters:

pnode_name (str) – Name of the P-Node.

finish_header(labels)[source]

Write P-Node dimensions in the header of the file.

Parameters:

labels (list) – Dimensions of the P-Node.

write()[source]

Writes P-Nodes contents.

write_header()[source]

Write the header of the file.

class core.file.FilePNodesSuccess(ident, file_name, node, **params)[source]

Bases: File

A file that records whether a P-node’s activation has been successful or not.

write()[source]

Write success.

write_header()[source]

Write the header of the file.

class core.file.FileSaveModels(ident, file_name, node, save_interval=100, **params)[source]

Bases: File

A file that triggers the saving of models in nodes.

close()[source]

Close de underlying file.

write()[source]

Method that writes the data in the file

write_header()[source]

Create the output folder.

class core.file.FileTrialsSuccess(ident, file_name, node, **params)[source]

Bases: File

A file that records whether a P-node’s activation has been successful or not.

write()[source]

Write success.

write_header()[source]

Write the header of the file.

class core.file.FileWorldModelSuccess(ident, file_name, node, **params)[source]

Bases: File

A file that records the success of the world model predictions.

write()[source]

Method that writes the data in the file

write_header()[source]

Write the header of the file.

Service client

Python script to implement a service client, which is responsible for sending requests to the services of the system.

class core.service_client.ServiceClient(*args: Any, **kwargs: Any)[source]

Bases: Node

A generic service client class.

send_request(**kwargs)[source]

Send a request to the service.

Parameters:

kwargs (dict) – Keyword arguments representing the request parameters.

Returns:

The response from the service.

Return type:

service_type.Response

class core.service_client.ServiceClientAsync(node: rclpy.node.Node, service_type, service_name, callback_group)[source]

Bases: object

A generic service client class.

send_request_async(**kwargs) rclpy.task.Future[source]

Send a request to the service using asyncio.

Parameters:

kwargs (dict) – Keyword arguments representing the request parameters.

Returns:

The response from the service.

Return type:

service_type.Response

Utils

Python script which implements auxiliary functions used into the scripts of the core.

class core.utils.EncodableDecodableEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum class that can be encoded and decoded to/from a normalized value.

classmethod decode(value, normalized=True) str[source]

Decodes a normalized class value back to the corresponding string.

Parameters:
  • value (float) – The encoded value to decode.

  • normalized (bool) – Whether the value is normalized, defaults to True.

Raises:

ValueError – If no matching class is found for the value.

Returns:

The string representation of the enum member.

Return type:

str

classmethod encode(value: str, normalized=True) float[source]

Encodes a string to a normalized class value.

Parameters:
  • value (str) – The string representation of the enum member.

  • normalized (bool) – Whether to normalize the encoded value, defaults to True.

Raises:

ValueError – If the provided value is not a valid enum member.

Returns:

The encoded value as a float

Return type:

float

core.utils.actuation_dict_to_msg(actuation_dict)[source]

Transform an actuation dictionary into a ROS message.

Parameters:

actuation_dict (dict) – Dictionary that contais the actuation signal.

Returns:

The ROS message with the actuation.

Return type:

cognitve_node_interfaces.msg.Actuation

core.utils.actuation_msg_to_dict(msg)[source]

Transform a ROS message that contains an actuation into a dictionary.

Parameters:

msg (cognitve_node_interfaces.msg.Actuation) – The ROS message with the perception.

Returns:

The dictionary with the actuation.

Return type:

dict

core.utils.class_from_classname(class_name)[source]

Return a class object from a class name.

Parameters:

class_name (str) – The name of the class.

Returns:

The class object.

Return type:

type

core.utils.compare_perceptions(input_1, input_2, thresh=0.01)[source]

Return True if both perceptions have the same value. False otherwise.

Parameters:
  • sensing (dict) – Sensing in the current iteration.

  • old_sensing (dict) – Sensing in the last iteration.

Returns:

Boolean that indicates if there is a sensorial change.

Return type:

bool

core.utils.dict_to_msg(msg, object_dict)[source]

Transform an object dictionary into a ROS message.

Parameters:
  • msg (cognitve_node_interfaces.msg.Perception or cognitve_node_interfaces.msg.Actuation) – Message to transform

  • object_dict (dict) – Dictionary that contais the data.

Returns:

The ROS message with the perception.

Return type:

cognitve_node_interfaces.msg.Perception or cognitve_node_interfaces.msg.Actuation

core.utils.msg_to_dict(msg)[source]

Transform a ROS message that contains an object list into a dictionary.

Parameters:

msg (cognitve_node_interfaces.msg.Perception or cognitve_node_interfaces.msg.Actuation) – The ROS message containing the object list.

Returns:

A dictionary representation of the object list.

Return type:

dict

core.utils.perception_dict_to_msg(perception_dict)[source]

Transform a perception dictionary into a ROS message.

Parameters:

perception_dict (dict) – Dictionary that contais the perceptions.

Returns:

The ROS message with the perception.

Return type:

cognitve_node_interfaces.msg.Perception

core.utils.perception_msg_to_dict(msg)[source]

Transform a ROS message that contains a perception into a dictionary.

Parameters:

msg (cognitve_node_interfaces.msg.Perception) – The ROS message with the perception.

Returns:

The dictionary with the perceptions.

Return type:

dict

core.utils.separate_perceptions(perception)[source]

Separate a dicionary with several perceptions in several ones with one perception.

Parameters:

perception (dict) – The dictionary with all perceptions.

Returns:

A list with the dictionaries.

Return type:

list