Ports and data encoding

Ports are a mean to describe data encoding at the input and the output of a circuit in an Experiment.

Encoding

enum perceval.utils._enums.Encoding(value)

Logical qubit encoding on photons

Valid values are as follows:

DUAL_RAIL = <Encoding.DUAL_RAIL: 0>

Dual rail encoding where a qubit is encoded as the position of 1 photon in 2 modes.

POLARIZATION = <Encoding.POLARIZATION: 1>

Qubit is encoding on a single photon polarization (horizontal / vertical) in 1 mode.

RAW = <Encoding.RAW: 4>

Raw encoding is the closest to photonics. It encodes a qubit as the presence of photons in 1 mode.

QUDIT2 = <Encoding.QUDIT2: 5>

Qudits are encoding multiple qubits in the location of a single photon in multiple modes. QUDIT2 encodes 2 qubits on 1 photon in 4 modes.

QUDIT3 = <Encoding.QUDIT3: 6>

Encodes 3 qubits on 1 photon in 8 modes.

QUDIT4 = <Encoding.QUDIT4: 7>

Encodes 4 qubits on 1 photon in 16 modes.

QUDIT5 = <Encoding.QUDIT5: 8>

Encodes 5 qubits on 1 photon in 32 modes.

QUDIT6 = <Encoding.QUDIT6: 9>

Encodes 6 qubits on 1 photon in 64 modes.

QUDIT7 = <Encoding.QUDIT7: 10>

Encodes 7 qubits on 1 photon in 128 modes.

The Enum and its members also have the following methods:

property logical_length: int

Logical length of an encoding

property fock_length: int

Fock state length of an encoding

PortLocation

enum perceval.components.port.PortLocation(value)

Port positioning, at the beginning, the end of a given Experiment.

Valid values are as follows:

INPUT = <PortLocation.INPUT: 0>

Port is only at the input of the Experiment

OUTPUT = <PortLocation.OUTPUT: 1>

Port is only at the output of the Experiment

IN_OUT = <PortLocation.IN_OUT: 2>

Ports are often symmetrical, this value puts them in both locations.

Port

class perceval.components.port.Port(encoding, name)

A port attached to one or more modes

Parameters:
  • encoding (Encoding) – The corresponding qubit encoding

  • name (str) – The port’s name

property encoding

The port encoding

output_mode_type()

Return the mode type induced by the port

Return type:

ModeType

Herald

class perceval.components.port.Herald(value, name=None)

A fixed input or an herald (output) attached to a single mode.

Parameters:
  • value (int) – Expected input photon / output detection

  • name (str | int) – Optional herald name. Can be fixed or autogenerated as ‘herald{int}’

property expected
Returns:

the expected output photon / output detection

output_mode_type()

Return the mode type induced by the port

Return type:

ModeType

property user_given_name
Returns:

the herald name if it was fixed by the user. None otherwise

Utilitary functions

perceval.components.port.get_basic_state_from_ports(ports, state, add_herald_and_ancillary=False)

Convert a LogicalState to a BasicState by taking in account a port list

Parameters:
  • ports (list[APort]) – port list.

  • state (LogicalState) – the logical state to convert

  • add_herald_and_ancillary (bool) – add the herald and ancillary port to the basic state. Default to False.

Return type:

BasicState

Returns:

the converted Fock state

perceval.components.port.get_basic_state_from_encoding(encoding, logical)

Convert a LogicalState to a BasicState from an encoding list.

Parameters:
  • encoding (list[Encoding | int]) – encoding list

  • logical (LogicalState) – the logical state to convert

Raises:
  • TypeError – if encoding contains unsupported types

  • ValueError – if the encoding and logical state sizes do not match

Return type:

BasicState

Returns:

the converted Fock state