pygsti.algorithms.compilers.compile_symplectic

pygsti.algorithms.compilers.compile_symplectic#

compile_symplectic(s, pspec=None, absolute_compilation=None, paulieq_compilation=None, qubit_labels=None, iterations=20, algorithms=None, costfunction='2QGC:10:depth:1', paulirandomize=False, aargs=None, check=True, rand_state=None)#

Creates a Circuit that implements a Clifford gate given in the symplectic representation.

Returns an n-qubit circuit that implements an n-qubit Clifford gate that is described by the symplectic matrix s and some vector p. The circuit created by this function will be over the gates in the processor specification pspec, respecting any desired connectivity if a QubitProcessorSpec object is provided. Otherwise, the circuit is over the gates of a canonical processor containing all-to-all CNOTs, Hadamard, Phase, 3 products of Hadamard and Phase, and the Pauli gates.

Parameters:
  • s (array over [0,1]) – An (2n X 2n) symplectic matrix of 0s and 1s integers.

  • pspec (QubitProcessorSpec, optional) –

    An nbar-qubit QubitProcessorSpec object that encodes the device that s is being compiled for, where nbar >= n. If this is specified, the output circuit is over the gates available in this device. If this is None, the output circuit is over the “canonical” processor of CNOT gates between all qubits, consisting of “H”, “HP”, “PH”, “HPH”, “I”, “X”, “Y” and “Z”, which is the set used internally for the compilation.

    If nbar > n it is necessary to provide qubit_labels, that specifies which of the qubits in pspec the Clifford acts on. (All other qubits will not be part of the returned circuit, regardless of whether that means an over-head is required to avoid using gates that act on those qubits. If these additional qubits should be used, then the input s needs to be “padded” to be the identity on those qubits).

    The indexing s is assumed to be the same as that in the list pspec.qubit_labels, unless qubit_labels is specified. Then, the ordering is taken w.r.t the ordering of the list qubit_labels.

  • absolute_compilation (CompilationRules) – Rules for exactly (absolutely) compiling the “native” gates of pspec into clifford gates.

  • paulieq_compilation (CompilationRules) – Rules for compiling, up to single-qubit Pauli gates, the “native” gates of pspec into clifford gates.

  • qubit_labels (list, optional) – Required if the Clifford to compile is over less qubits than pspec. In this case this is a list of the qubits to compile the Clifford for; it should be a subset of the elements of pspec.qubit_labels. The ordering of the qubits in (s,`p`) is taken w.r.t the ordering of this list.

  • iterations (int) – Some of the allowed algorithms are randomized. This is the number of iterations used in each algorithm specified that is a randomized algorithm.

  • algorithms (list of strings, optional) –

    Specifies the algorithms used. Defaults to [‘ROGGE’]. If more than one algorithm is specified, then all the algorithms are implemented and the lowest “cost” circuit obtained from all the algorithms (and iterations of those algorithms, if randomized) is returned.

    The allowed elements of this list are:

    • ’BGGE’: A basic, deterministic global Gaussian elimination algorithm. Circuits obtained from this algorithm

      contain, in expectation, O(n^2) 2-qubit gates. Although the returned circuit will respect device connectivity, this algorithm does not take connectivity into account in an intelligent way. More details on this algorithm are given in compile_symplectic_with_ordered_global_gaussian_elimination(); it is the algorithm described in that docstring but with the qubit ordering fixed to the order in the input s.

    • ’ROGGE’: A randomized elimination order global Gaussian elimination algorithm. This is the same algorithm as

      ’BGGE’ except that the order that the qubits are eliminated in is randomized. This results in significantly lower-cost circuits than the ‘BGGE’ method (given sufficiently many iterations). More details are given in the compile_symplectic_with_random_ordered_global_gaussian_elimination() docstring.

    • ’iAGvGE’: Our improved version of the Aaraonson-Gottesman method for compiling a symplectic matrix, which

      uses 3 CNOT circuits and 3 1Q-gate layers (rather than the 5 CNOT circuit used in the algorithm of AG in Phys. Rev. A 70 052328 (2004)), with the CNOT circuits compiled using Gaussian elimination. Note that this algorithm appears to perform substantially worse than ‘ROGGE’, even though with an upgraded CNOT compiler it is asymptotically optimal (unlike any of the GGE methods). Also, note that this algorithm is randomized: there are many possible CNOT circuits (with non-equivalent action, individually) for the 2 of the 3 CNOT stages, and we randomize over those possible circuits. This randomization is equivalent to the randomization used in the stabilizer state/measurement compilers.

  • costfunction (function or string, optional) –

    If a function, it is a function that takes a circuit and pspec as the first and second inputs and returns a cost (a float) for the circuit. The circuit input to this function will be over the gates in pspec, if a pspec has been provided, and as described above if not. This costfunction is used to decide between different compilations when randomized algorithms are used: the lowest cost circuit is chosen. If a string it must be one of:

    • ’2QGC’ : the cost of the circuit is the number of 2-qubit gates it contains.

    • ’depth’ : the cost of the circuit is the depth of the circuit.

    • ’2QGC:x:depth:y’the cost of the circuit is x * the number of 2-qubit gates in the circuit +

      y * the depth of the circuit, where x and y are integers.

  • paulirandomize (bool, optional) – If True then independent, uniformly random Pauli layers (a Pauli on each qubit) are inserted in between every layer in the circuit. These Paulis are then compiled into the gates in pspec, if pspec is provided. That is, this Pauli-frame-randomizes / Pauli-twirls the internal layers of this Clifford circuit. This can be useful for preventing coherent addition of errors in the circuit.

  • aargs (dict, optional) – If the algorithm can take optional arguments, not already specified as separate arguments above, then the list arrgs[algorithmname] is passed to the compile_symplectic algorithm as its final arguments, where algorithmname is the name of algorithm specified in the list algorithms.

  • check (bool, optional) – Whether to check that the output circuit implements the correct symplectic matrix (i.e., tests for algorithm success).

  • rand_state (RandomState, optional) – A np.random.RandomState object for seeding RNG

Returns:

A circuit implementing the input Clifford gate/circuit.

Return type:

Circuit