parityos.encodings
- class parityos.encodings.mappings.Mappings(encoding_map: dict[Qubit, ParityMap], decoding_map: dict[Qubit, ParityMap])
Holds the Parity Architecture encoding and decoding maps returned from the API.
- Parameters:
encoding_map – the encoding map, which tells you how to go from each physical qubit to the logical qubits that it encodes.
decoding_map – A possible decoding map, which tells you how to go from a logical qubit to a list of physical qubits that multiply to the logical qubit.
- classmethod from_json(data: Mapping[str, str | int | float | bool | None | dict[str, JSONType] | list[JSONType]]) Self
Constructs a Mappings object from json data
- Parameters:
data – the mappings in json format
- Returns:
a Mappings object
- property logical_degeneracies: list[ParityMap]
Logical degeneracies are symmetries in the logical Hamiltonian and show up in the decoding map as entries where the map does not have any qubits. The logical Hamiltonian is equivalent to a Hamiltonian where the logical degeneracies are mapped out using their trivial mapping to a parity.
- to_json() dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None | dict[str, JSONType] | list[JSONType]] | list[str | int | float | bool | None | dict[str, JSONType] | list[JSONType]]]
Converts a Mappings object to json
- Returns:
the mappings in json format
- class parityos.encodings.mappings.ParityMap(qubits: frozenset[Qubit], parity: int)
A class that represents a set of qubits and a parity value, to facilitate serialization of Mappings.
- classmethod from_json(data: Sequence[str | int | float | bool | None | dict[str, JSONType] | list[JSONType]]) Self
Initializes a ParityMap object from json
- Parameters:
data – parity map in json format
- Returns:
A ParityMap instance
- to_json() list[str | int | float | bool | None | dict[str, str | int | float | bool | None | dict[str, JSONType] | list[JSONType]] | list[str | int | float | bool | None | dict[str, JSONType] | list[JSONType]]]
Converts a Parity Map object to json
- Returns:
the parity map in json format
- class parityos.encodings.parity_encoder.ParityEncoderExtension
Extends the ParityOSOutput class with the encode method, which transforms a qubit Z-spin configuration given in the logical system to the Z-spin configuration for the parity qubits (i.e. for the physical system).
- encode(configuration: dict[Qubit, int]) dict[Qubit, int]
Converts a given configuration in the logical system to a bitstring for the physical mapping
- Parameters:
configuration – A logical configuration to encode, the keys refer to logical qubits; the values are either +1 or -1.
- Returns:
The configuration on the physical qubits.
- class parityos.encodings.parity_decoder.ParityDecoderExtension
Extends the ParityOSOutput class with the methods decode, error_correct, select_reduced_readout_qubits and make_full_configuration_from_partial. These methods can decode physical configurations into logical configurations.
It is possible to use a partial read-out to construct a full physical configuration, based on the redundant encoding that the parity architecture offers. This is especially useful if only a limited number of qubits can be read out in the hardware setup, or if the read-out failed on some qubits.
- decode(configuration: dict[Qubit, int]) list[dict[Qubit, int]]
Decodes a physical configuration back to a logical one, it is important that the configuration contains enough qubits to reconstruct the logical state. If not enough qubits are included, a ParityOSException will be raised.
- Parameters:
configuration – A physical configuration to decode, the keys are qubits on the physical device, the values are either +1 or -1.
- Returns:
A list containing all equally-likely logical configuration that correspond to the physical configuration. Each logical configuration is a dictionary going from qubit, to +1 or -1, similar to the physical configuration.
- error_correct(configuration: dict[Qubit, int]) list[dict[Qubit, int]]
Correct errors using the nearest neighbor algorithm
- Parameters:
configuration – a physical configuration to correct for errors
- Returns:
A list of possible physical configurations that satisfy all constraints (and hence are part of the physical code subspace), which each were obtained at the smallest possible Hamming distance from the original configuration.
- make_full_configuration_from_partial(configuration: dict[Qubit, int], return_incomplete: bool = False) dict[Qubit, int]
Reconstructs a full physical configuration from a partial one using the constraints in the compiled problem.
- Parameters:
configuration – A partial physical configuration to extend.
return_incomplete – If this flag is set to True, we return a physical configuration even if the full configuration could not be reconstructed. The configuration returned in that case contains all the qubits that could be deduced.
- Returns:
Full physical configuration deduced from the parity constraints.
- select_reduced_readout_qubits(random_generator: Random = None) set[Qubit]
Constructs a random minimal set of qubits that can be read-out and still be used to recover the full logical configuration.
Note that when these qubits are used for read-out, no error correction can be applied.
- Parameters:
random_generator – Optional. A random number generator that has a
`choice`
method. If None is given, then the default random number generator from the random standard library is used instead.- Returns:
A random set of qubits that are selected for read-out.