simplify

Circuit simplification

Several strategies to simplify a circuit exist. Perceval circuit simplification takes a circuit and does the following:

  • For phase shifters, add their phase if they are not parameters and combine them into a single phase shifter (work through permutations). If display == False, removes them if their added phase is \(0\) or \(2\pi\).

  • For Permutations, if two permutations are consecutive, they are combined into a single permutation. For single permutations, fixed modes at the extremities are removed. If they are not just consecutive, try to compute a “better” permutation, then if it is better, move the components accordingly to this new permutation. Display changes how a permutation is evaluated.

Example:

>>> from perceval.utils.algorithms.simplification import simplify
>>> from perceval import Circuit, PERM, PS
>>> circuit = Circuit(6) // PERM([3,2,1,0]) // (1, PERM([4,1,3,2,0])) // PS(phi=0.6) // PS(phi=0.2)
>>> print(circuit.ncomponents())
4
>>> simplified_circuit = simplify(circuit, display = False)
>>> print(simplified_circuit.ncomponents())
2

simplify code reference

perceval.utils.algorithms.simplification.simplify(circuit, m=None, display=False)

Simplify a circuit when possible

Parameters:
  • circuit (list | ACircuit) –

    the circuit to simplify. This input can be:

    • a unitary Circuit

    • a list of positioned components. These components do not have to be unitary (e.g. [((0,1), BS()), ((0,), PS(phi=0.5)), ((1,), TD(1))])

  • m (int) – the circuit size (in modes), required only when circuit is a list.

  • display (bool) – Slightly changes the behaviour of the function, give a circuit which is displayed more similarly than the input. Use False when computing. Default is False.

Return type:

list | Circuit

Returns:

The simplified circuit (same type as the input)