QUnits

qrobot.qunits module class diagram:


The BaseUnit abstract class

class qrobot.qunits.base.BaseUnit(name: str, Ts: float)[source]

Base abstract class defining the multithreading and redis festures implemented by all the units.

Parameters:
  • name (str) – The unit name

  • Ts (float) – The time period with wich the unit execute its task

id

The unique instance identifier of the unit

Type:

str

name

The unique instance identifier of the unit

Type:

str

Ts

The time period for which the unit execute its task

Type:

float

start() None[source]

Starts the unit’s background threads

stop() None[source]

Stops the unit’s background threads


BaseUnit Globals

qrobot.qunits.base.MIN_TS = 0.01

Minimum time period allowed (in seconds).

Type:

float


The QUnit class

class qrobot.qunits.QUnit(name: str, model: Model, burst: Burst, Ts: float, query: list | None = None, in_qunits: Dict[int, str] | None = None, default_input: float | None = None)[source]

[QUnit description]

Parameters:
  • name (str) – The qUnit name

  • model (qrobot.models.Model) – The model the qUnit implements

  • burst (qrobot.bursts.Burst) – The burst the qUnit implements

  • Ts (float) – The sampling time with wich the qUnit reads the input

  • query (list, optional) – The target state for the model queries. Defaults to None

  • in_units (dict[int, str], optional) – Dictionary containing {dim : qunit_id} inputs couplings, i.e. qunit_id output is the input for dimension dim. Defaults to None.

  • default_input (List[float]) – Default input vector of scalar values to use as default value when qunit does not have an available one. Defaults to model.n*[0.0]

id

The unique instance identifier of the qUnit

Type:

str

name

The unique instance identifier of the qUnit

Type:

str

model

The model which the qUnit implements

Type:

qrobot.models.Model

burst

The burst the qUnit implements

Type:

qrobot.bursts.Burst

Ts

The sampling period for which the qUnit samples an event

Type:

float

default_input

Default input vector of scalar values to use as default value when qunit does not have an available one

Type:

List[float]

get_burst_output() float | None[source]

Get the latest burst output from the qUnit

Returns:

The latest burst output written by the unit on the Redis database

Return type:

float

property in_qunits: Dict[int, str]

Current output {dim : qunit_id} couplings.

Returns:

The current output {dim : qunit_id} couplings dictionary

Return type:

dict

property input_vector: List[float]

The current input vector of the unit

Returns:

The current input vector

Return type:

list

property query: List[float]

Current target state for the model queries

Returns:

The query target state array in the computational basis

Return type:

list

set_input(dim: int, qunit_id: str) None[source]

Set a new input qunit for the desired dimension

Parameters:
  • dim (int) – The input dimension index

  • qunit_id (str) – The input qunit id


The SensorialUnit class

class qrobot.qunits.SensorialUnit(name: str, Ts: float, default_input: float = 0)[source]

Unit periodically sending normalized scalar readings.

Parameters:
  • name (str) – The SensorialUnit name

  • Ts (float) – The sampling time with wich the SensorialUnit reads the input

  • default_input (float) – Default input for the scalar readings when the SensorialUnit does not have an available one. Defaults to 0

id

The unique instance identifier of the SensorialUnit

Type:

str

name

The unique instance identifier of the SensorialUnit

Type:

str

Ts

The sampling period for which the SensorialUnit samples an event

Type:

float

default_input

Default input for the scalar readings when the SensorialUnit does not have an available one

Type:

float

property scalar_reading: float

Current scalar reading.


Redis utilities

The module qrobot.qunits.redis_utils contains useful functions to connect and to manage the redis database.

qrobot.qunits.redis_utils.get_redis(host: str = 'localhost', port: int = 6379, database: int = 0) Redis[source]

Returns a redis-py Redis client.

Parameters:
  • host (str) – Redis server hostname. Defaults to “localhost”.

  • port (int) – Redis server port. Defaults to 6379.

  • database (int) – Redis database. Defaults to 0.

Returns:

redis-py Redis client

Return type:

redis.Redis

See also

redis.Redis

redis-py Redis client class

qrobot.qunits.redis_utils.flush_redis(host: str = 'localhost', port: int = 6379, database: int = 0) None[source]

Flush the redis database.

Parameters:
  • host (str) – Redis server hostname. Defaults to “localhost”.

  • port (int) – Redis server port. Defaults to 6379.

  • database (int) – Redis database. Defaults to 0.

qrobot.qunits.redis_utils.redis_status(host: str = 'localhost', port: int = 6379, database: int = 0) dict[source]

Returns the current redis database status in the for of a dictionary with {db_key : db_value} mapping.

Parameters:
  • host (str) – Redis server hostname. Defaults to “localhost”.

  • port (int) – Redis server port. Defaults to 6379.

  • database (int) – Redis database. Defaults to 0.

Returns:

Redis current status

Return type:

dict