qgym.utils package

Generic utils for the Reinforcement Learning QGym.

class qgym.utils.GateEncoder[source]

Bases: object

Learns a set of gates and creates a mapping to integers and back.

__init__()[source]

Initialize the GateEncoder.

__repr__()[source]

Make a string representation without endline characters.

Return type:

str

decode_gates(encoded_gates)[source]

Decode integer encoded gate names to the original gate names based on the gates seen in learn_gates.

Parameters:
Raises:

TypeError – When an unsupported type is given

Return type:

str | dict[str, Any] | list[Gate] | set[str] | list[str]

Returns:

Decoded version of encoded_gates. The output structure should resemble the input structure. So a Mapping will return a Dict, while a single int will return a str.

encode_gates(gates)[source]

Encode the gate names (of type str) in gates to integers, based on the gates seen in learn_gates.

Parameters:

gates (str | Mapping[str, Any] | Sequence[Gate] | set[str] | list[str] | tuple[str, ...]) – Gates to encode. The input type determines the return type.

Raises:

TypeError – When an unsupported type is given.

Return type:

int | dict[int, Any] | list[Gate] | set[int] | list[int]

Returns: Integer encoded version of gates. The output structure should resemble

the input structure. So a Mapping will return a Dict, while a single str will return an int.

learn_gates(gates)[source]

Learns the gates names from an Iterable and creates a mapping from unique gate names to integers and back.

Parameters:

gates (Iterable[str]) – Iterable containing the names of the gates that should be learned. The Iterable can contain duplicate names.

Return type:

GateEncoder

Returns:

Self.