ObservationStash#

Module: exa.core.observation.observation_stash

class ObservationStash(local_observations, db_observations, compare_db_and_local_time=None)#

Bases: object

Class for saving local observations in the runtime instead of the DB.

Parameters:
  • local_observations (Mapping[str, Sequence[LocalObservation]]) – Dictionary mapping lists of local observations to their dut field path (The full one which includes the component name). Duplicates are removed.

  • db_observations (Mapping[str, Sequence[ObservationData]]) – Dictionary mapping lists of db observations to their dut field path (The full one which includes the component name). Duplicates are removed. The DB observations will be returned by get_latest_observation() in case there is no local observation for that dut_field found.

  • compare_db_and_local_time (bool | None) – Allow comparing local and database timestamps when fetching latest observations. If disabled, local observations will always have priority to database observations, and a warning will be shown in case a database observation may be more recent. Setting the flag explicitly to ´False´ Suppresses the warning. Disabled by default.

Methods

copy

Copies the observation stash.

from_observation_set

Create an observation stash containing latest observations from the DB filtered using set_id.

from_tags

Create an observation stash containing latest observations from the DB filtered using tags.

get_db_observations

Get the DB observations stored in the stash.

get_latest_observation

Gives the latest observation for the specified name (i.e. DUT field path).

get_latest_observations

Get the latest local or DB observations stored in the stash.

get_local_observations

Get the local observations stored in the stash.

merge_to

Merge the local observations from self to another stash.

modify_tags

Tag observations in the stash.

save

Saves the local observations to the DB.

set_observation_value

Change the value of an observation in the stash by adding a new LocalObservation.

stash

Adds local observations to the stash.

static from_tags(tags=())#

Create an observation stash containing latest observations from the DB filtered using tags.

Only contains observations for the dut_id of the station.

Parameters:

tags (Iterable[Iterable[str]]) – Observation tags to choose which observations to load. Outer iterable is a short-circuit OR, inner is AND. Example: [['awesome', 'monday'], ['base']] means “For every observation (dut_field) we need, first try to load the latest such observation that is tagged with both 'awesome' AND 'monday'. If one with these tags cannot be found, try finding one tagged with 'base'” instead. If tags is empty, no observations will be loaded.

Returns:

observation stash containing the requested observations

Return type:

ObservationStash

static from_observation_set(set_id)#

Create an observation stash containing latest observations from the DB filtered using set_id.

Only contains observations for the dut_id of the station.

Parameters:

set_id (UUID) – The observation set ID for which to load observations.

Returns:

observation stash containing the requested observations

Return type:

ObservationStash

copy()#

Copies the observation stash.

Return type:

ObservationStash

stash(observations)#

Adds local observations to the stash.

Only observations not yet found in self are added.

Parameters:

observations (LocalObservation | list[LocalObservation]) – A list of observations or a singular observation to be added.

Return type:

None

get_latest_observation(dut_field, tags=None, set_ids=None)#

Gives the latest observation for the specified name (i.e. DUT field path).

By default, any local observations added to the stash are considered more recent than database observations stored in the stash when initialising it. This can be altered using the compare_local_and_db_time flag when initializing the ObservationStash

Parameters:
  • dut_field (str) – The full DUT field path of the observation, including the component name.

  • tags (list[str] | None) – The tags used for filtering the observations.

  • set_ids (list[UUID] | None) – TODO

Returns:

The latest observation.

Return type:

ObservationDefinition | None

get_local_observations(components=None, observations=None, tags=None)#

Get the local observations stored in the stash.

Parameters:
  • components (list[str] | None) – Components for which to get the observations. If not provided, will get for all components.

  • observations (list[str] | None) – Observation parameter names for which to get the observations. If not provided, will get for all observation parameters.

  • tags (list[str] | None) – If provided, will get only the observations containing these tags.

Return type:

dict[str, list[LocalObservation]]

get_db_observations(components=None, observations=None, tags=None, set_ids=None)#

Get the DB observations stored in the stash.

Parameters:
  • components (list[str] | None) – Components for which to get the observations. If not provided, will get for all components.

  • observations (list[str] | None) – Observation parameter names for which to get the observations. If not provided, will get for all observation parameters.

  • tags (list[str] | None) – If provided, will get only the observations containing these tags.

  • set_ids (list[UUID] | None) – If provided, will get only the observations associated with the given set ids. Can not be used together with tags.

Return type:

dict[str, list[ObservationData]]

get_latest_observations(components=None, observations=None, tags=None)#

Get the latest local or DB observations stored in the stash.

Parameters:
  • components (list[str] | None) – Components for which to get the latest observations. If not provided, will get for all components.

  • observations (list[str] | None) – Observation parameter names for which to get the latest observations. If not provided, will get for all observation parameters.

  • tags (list[str] | None) – If provided, will get only the latest observations containing these tags.

Return type:

dict[str, ObservationDefinition]

modify_tags(tags_to_add=None, tags_to_remove=None, components=None, observations=None, tags=None)#

Tag observations in the stash.

Parameters:
  • tags_to_add (list[str] | None) – Tags to be added.

  • tags_to_remove (list[str] | None) – Tags to be removed.

  • components (list[str] | None) – Components for which to add/remove tags. If not provided, will apply to all components.

  • observations (list[str] | None) – Observations for which to add/remove tags. If not provided, will apply to all observations.

  • tags (list[str] | None) – Tags for which to add/remove more tags.

Return type:

None

merge_to(other, components=None, observations=None, tags=None, only_latest=False)#

Merge the local observations from self to another stash.

Parameters:
  • other (ObservationStash) – The stash into which to merge the local observations.

  • components (list[str] | None) – Components for which to merge the observations. If not provided, will merge for all components.

  • observations (list[str] | None) – Observation parameter names for which to merge the observations. If not provided, will merge for all observation parameters.

  • tags (list[str] | None) – If provided, will merge only the observations containing these tags.

  • only_latest (bool) – Option to merge only the latest observation per dut field.

Return type:

None

save(components=None, observations=None, tags=None, new_tags=None, only_latest=False, convert_to_db_observations=False, storage=None)#

Saves the local observations to the DB.

Parameters:
  • components (list[str] | None) – Components for which to save the observations. If not provided, will save for all components.

  • observations (list[str] | None) – Observation parameter names for which to save the observations. If not provided, will save for all observation parameters.

  • tags (list[str] | None) – If provided, will save only the observations containing these tags.

  • new_tags (list[str] | None) – Optionally tag the observations with these tags when saving.

  • only_latest (bool) – Option to save only the latest observation per dut field.

  • convert_to_db_observations (bool) – If set True, moves the saved observations as DB observations, so that they cannot be saved again from this same stash.

  • storage (StorageInterface | None) – If given, overrides the default (ambient) storage backend for this call.

Returns:

The saved observations as in a list of DB observations.

Return type:

list[ObservationData]

set_observation_value(dut_field, value)#

Change the value of an observation in the stash by adding a new LocalObservation.

Parameters:
  • dut_field (str) – The full DUT field path of the observation, including the component name.

  • value (Annotated[bool | str | int | float | complex | ndarray, PlainValidator(func=~exa.common.data.value.validate_value, json_schema_input_type=~typing.Any), PlainSerializer(func=~exa.common.data.value.serialize_value, return_type=PydanticUndefined, when_used=always), WithJsonSchema(json_schema={}, mode=None)]) – The new value for the observation.

Return type:

None

Inheritance

Inheritance diagram of exa.core.observation.observation_stash.ObservationStash