parityos.encodings

class parityos.encodings.mappings.Mappings(logical_degeneracies: List[ParityMap], encoding_map: Mapping[Qubit, ParityMap], decoding_map: Mapping[Qubit, ParityMap])

Holds the Parity Architecture encoding and decoding maps returned from the API.

Parameters:
  • logical_degeneracies – the list of how logical degeneracies are fixed

  • 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.

__init__(logical_degeneracies: List[ParityMap], encoding_map: Mapping[Qubit, ParityMap], decoding_map: Mapping[Qubit, ParityMap]) None
classmethod from_json(data: Mapping[str, str | int | float | bool | None | Dict[str, Any] | List[Any]])

Constructs a Mappings object from json data

Parameters:

data – the mappings in json format

Returns:

a Mappings object

to_json()

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.

__init__(qubits: FrozenSet[Qubit], parity: int) None
classmethod from_json(data)

Initializes a ParityMap object from json

Parameters:

data – parity map in json format

Returns:

A ParityMap instance

to_json()

Converts a Parity Map object to json

Returns:

the parity map in json format

class parityos.encodings.parity_encoder.ParityEncoderExtension

An extends the ParityOSOutput class with the encode method. This method can transform a bitstring given in the logical system to the parity encoding (i.e. to 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 are qubits on the physical device, the values are either +1 or -1.

Returns:

The configuration in the physical system.

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() List[Qubit]

Constructs a random minimal list 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.

Returns:

A random list of qubits that are selected for read-out.