Logical State

A LogicalState represents a pure qubit state. It is a list of 0s and 1s.

Their main purpose is to provide an easy way to convert a qubit state to a BasicState.

They can be used in two ways:

  • With Port

    >>> import perceval as pcvl
    >>> encodings = [pcvl.Encoding.DUAL_RAIL, pcvl.Encoding.QUDIT2]
    >>> ports = [pcvl.Port(encoding, "my_name") for encoding in encodings]
    >>> ls = pcvl.LogicalState("101")
    >>> print(pcvl.get_basic_state_from_ports(ports, ls))
    |0,1,0,1,0,0>
    
  • With Processor, Experiment or RemoteProcessor that has Ports defined (recommended when using composition):

    >>> import perceval as pcvl
    >>> encodings = [pcvl.Encoding.DUAL_RAIL, pcvl.Encoding.QUDIT2]
    >>> e = pcvl.Experiment(6)
    >>> m = 0
    >>> for i, encoding in enumerate(encodings):
    >>>     e.add_port(m, pcvl.Port(encoding, f"{i}"))
    >>>     m += encoding.fock_length
    >>> ls = pcvl.LogicalState([1, 0, 1])
    >>> e.with_input(ls)
    >>> print(e.input_state)
    |0,1,0,1,0,0>
    

Note that the way a LogicalState is converted depends on the encoding, and the number of modes, photons, and the expected number of qubits is only guaranteed by the encoding, not by the conversion itself.

Note

The perceval convention for LogicalStates is that the first digit is represented in the first mode(s) of a circuit.

class perceval.utils.logical_state.LogicalState(state=None)

Represent a Logical state

Parameters:

state (Optional[list[int]]) – Can be either None, a list or a str, defaults to None (empty list)

Raises:
  • ValueError – Must have only 0 and 1 in a state

  • TypeError – Supports only None, list or str as state type

perceval.utils.logical_state.generate_all_logical_states(n)

Generate all Logical states of size n

Parameters:

n (int) – Size of the Logical states to generate

Return type:

list[LogicalState]

Returns:

List of all \(2^n\) Logical states of size n