def to_tket(self):
     if self.out_par != mat22partition(Mat2.id(self.n_qubits)):
         print(self.out_par)
         raise NotImplementedError("The linear transformation part of the phase polynomial cannot yet be transformed into a tket circuit")
     circuit = TketCircuit(self.n_qubits)
     for parity, phase in self.zphases.items():
         qubits = [i for i,s in enumerate(parity) if s == '1']
         circuit.add_pauliexpbox(PauliExpBox([Pauli.Z]*len(qubits), phase), qubits)
     # TODO add the linear combination part with CNOTs
     Transform.DecomposeBoxes().apply(circuit)
     return circuit
Beispiel #2
0
def h2_JW_sto3g_ansatz():
    symbols = [Symbol("s0"), Symbol("s1"), Symbol("s2")]
    ansatz = Circuit(4)
    # Initialise in Hartree-Fock state
    ansatz.X(0)
    ansatz.X(1)
    # Single excitations
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.X, Pauli.Z, Pauli.Y, Pauli.I], -symbols[0]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.Y, Pauli.Z, Pauli.X, Pauli.I], symbols[0]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.I, Pauli.X, Pauli.Z, Pauli.Y], -symbols[1]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.I, Pauli.Y, Pauli.Z, Pauli.X], symbols[1]),
        [0, 1, 2, 3])
    # Double excitations
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.X, Pauli.X, Pauli.X, Pauli.Y], -symbols[2]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.X, Pauli.X, Pauli.Y, Pauli.X], -symbols[2]),
        [0, 1, 2, 3])

    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.X, Pauli.Y, Pauli.X, Pauli.X], symbols[2]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.Y, Pauli.X, Pauli.X, Pauli.X], symbols[2]),
        [0, 1, 2, 3])

    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.X, Pauli.Y, Pauli.Y, Pauli.Y], -symbols[2]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.Y, Pauli.X, Pauli.Y, Pauli.Y], -symbols[2]),
        [0, 1, 2, 3])

    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.Y, Pauli.Y, Pauli.X, Pauli.Y], symbols[2]),
        [0, 1, 2, 3])
    ansatz.add_pauliexpbox(
        PauliExpBox([Pauli.Y, Pauli.Y, Pauli.Y, Pauli.X], symbols[2]),
        [0, 1, 2, 3])
    # Synthesise structures into primitive gates
    DecomposeBoxes().apply(ansatz)
    return ansatz, symbols