Skip to content

Frame

Bases: Mapping[str, object], Displayable

A record of the state of the simulation at a given time.

The core functionality is a dict that relates keys to stateful objects. It is highly recommended that users not modify Frame._data directly, and instead use update() to return an updated copy instead.

The log can be accessed with the key "log", and any expired key will instead return the string "EXPIRED" (although the object could still be retrieved from the underlying Frame._data).

Examples:

>>> from loqs.core import Frame
>>> f = Frame({"qubits": [0, 1, 2]}, log="Init Step")
>>> f["qubits"]
[0, 1, 2]
>>> f.log
'Init Step'

Frame

Frame(data: FrameLike = None, log: str = 'N/A')

Parameters:

Name Type Description Default
data FrameLike

A dict-like object with frame data. Defaults to None, which initializes an empty frame.

None
log str

See log.

'N/A'

Attributes

Name Type Value Doc
log str unset Log string for better printing.

decode

Inherited static method from Serializable.decode().


display

Inherited method from Displayable.display().


dump

Inherited method from Serializable.dump().


encode

Inherited static method from Serializable.encode().


expire

expire(key: str) -> None

Mark a key as expired.

This will cause the key to return "EXPIRED" instead of the stored object, although the object is still stored internally.

Parameters:

Name Type Description Default
key str

The key to expire

required

get

Inherited method from Mapping.


items

Inherited method from Mapping.


keys

Inherited method from Mapping.


load

Inherited class method from Serializable.load().


no_serialize

no_serialize(key: str) -> None

Mark a key to not be serialized.

This will cause the key to be saved as "NOT SERIALIZED" during serialization.

Parameters:

Name Type Description Default
key str

The key to not serialize

required

read

Inherited class method from Serializable.read().


serialize_function

Inherited static method from Serializable.serialize_function().


update

update(new_data: Mapping[str, object] | None = None, new_log: str | None = None) -> Frame

Create a new Frame with updated data and log.

Any data/log that is unchanged will be carried over from the current Frame.

Parameters:

Name Type Description Default
new_data Mapping[str, object] | None

Any data to add/override from the old frame. Defaults to None, which changes no data.

None
new_log str | None

A new log string. Defaults to None, which keeps the old log.

None

Returns:

Type Description
Frame

A new Frame instance with updated data and log.

Examples:

>>> from loqs.core import Frame
>>> f0 = Frame({"data": 100})
>>> f1 = f0.update({"data": 200}, new_log="Updated step")
>>> f0["data"]
100
>>> f1["data"]
200

values

Inherited method from Mapping.


write

Inherited method from Serializable.write().