def test_multi_qubit_gates(self): """Test that a tape with Ising gates has the correct metric tensor tapes.""" dev = qml.device("default.qubit", wires=3) with qml.tape.JacobianTape() as tape: qml.Hadamard(0) qml.Hadamard(2) qml.IsingXX(0.2, wires=[0, 1]) qml.IsingXX(-0.6, wires=[1, 2]) qml.IsingZZ(1.02, wires=[0, 1]) qml.IsingZZ(-4.2, wires=[1, 2]) tapes, proc_fn = qml.metric_tensor(tape, approx="block-diag") assert len(tapes) == 4 assert [len(tape.operations) for tape in tapes] == [2, 4, 5, 6] assert [len(tape.measurements) for tape in tapes] == [1] * 4 expected_ops = [ [qml.Hadamard, qml.QubitUnitary], [qml.Hadamard, qml.Hadamard, qml.IsingXX, qml.QubitUnitary], [ qml.Hadamard, qml.Hadamard, qml.IsingXX, qml.IsingXX, qml.QubitUnitary ], [ qml.Hadamard, qml.Hadamard, qml.IsingXX, qml.IsingXX, qml.IsingZZ, qml.QubitUnitary ], ] assert [[type(op) for op in tape.operations] for tape in tapes] == expected_ops
def op(op_name): ops_list = { "RX": qml.RX(0.123, wires=0), "RY": qml.RY(1.434, wires=0), "RZ": qml.RZ(2.774, wires=0), "S": qml.S(wires=0), "SX": qml.SX(wires=0), "T": qml.T(wires=0), "CNOT": qml.CNOT(wires=[0, 1]), "CZ": qml.CZ(wires=[0, 1]), "CY": qml.CY(wires=[0, 1]), "SWAP": qml.SWAP(wires=[0, 1]), "ISWAP": qml.ISWAP(wires=[0, 1]), "SISWAP": qml.SISWAP(wires=[0, 1]), "SQISW": qml.SQISW(wires=[0, 1]), "CSWAP": qml.CSWAP(wires=[0, 1, 2]), "PauliRot": qml.PauliRot(0.123, "Y", wires=0), "IsingXX": qml.IsingXX(0.123, wires=[0, 1]), "IsingXY": qml.IsingXY(0.123, wires=[0, 1]), "IsingYY": qml.IsingYY(0.123, wires=[0, 1]), "IsingZZ": qml.IsingZZ(0.123, wires=[0, 1]), "Identity": qml.Identity(wires=0), "Rot": qml.Rot(0.123, 0.456, 0.789, wires=0), "Toffoli": qml.Toffoli(wires=[0, 1, 2]), "PhaseShift": qml.PhaseShift(2.133, wires=0), "ControlledPhaseShift": qml.ControlledPhaseShift(1.777, wires=[0, 2]), "CPhase": qml.CPhase(1.777, wires=[0, 2]), "MultiRZ": qml.MultiRZ(0.112, wires=[1, 2, 3]), "CRX": qml.CRX(0.836, wires=[2, 3]), "CRY": qml.CRY(0.721, wires=[2, 3]), "CRZ": qml.CRZ(0.554, wires=[2, 3]), "Hadamard": qml.Hadamard(wires=0), "PauliX": qml.PauliX(wires=0), "PauliY": qml.PauliY(wires=0), "PauliZ": qml.PauliZ(wires=0), "CRot": qml.CRot(0.123, 0.456, 0.789, wires=[0, 1]), "DiagonalQubitUnitary": qml.DiagonalQubitUnitary(np.array([1.0, 1.0j]), wires=1), "ControlledQubitUnitary": qml.ControlledQubitUnitary( np.eye(2) * 1j, wires=[0], control_wires=[2] ), "MultiControlledX": qml.MultiControlledX(wires=(0, 1, 2), control_values="01"), "SingleExcitation": qml.SingleExcitation(0.123, wires=[0, 3]), "SingleExcitationPlus": qml.SingleExcitationPlus(0.123, wires=[0, 3]), "SingleExcitationMinus": qml.SingleExcitationMinus(0.123, wires=[0, 3]), "DoubleExcitation": qml.DoubleExcitation(0.123, wires=[0, 1, 2, 3]), "DoubleExcitationPlus": qml.DoubleExcitationPlus(0.123, wires=[0, 1, 2, 3]), "DoubleExcitationMinus": qml.DoubleExcitationMinus(0.123, wires=[0, 1, 2, 3]), "QFT": qml.QFT(wires=0), "QubitSum": qml.QubitSum(wires=[0, 1, 2]), "QubitCarry": qml.QubitCarry(wires=[0, 1, 2, 3]), "QubitUnitary": qml.QubitUnitary(np.eye(2) * 1j, wires=0), } return ops_list.get(op_name)
def circuit_ansatz(params, wires): """Circuit ansatz containing all the parametrized gates""" qml.QubitStateVector(unitary_group.rvs(2**4, random_state=0)[0], wires=wires) qml.RX(params[0], wires=wires[0]) qml.RY(params[1], wires=wires[1]) qml.RX(params[2], wires=wires[2]).inv() qml.RZ(params[0], wires=wires[3]) qml.CRX(params[3], wires=[wires[3], wires[0]]) qml.PhaseShift(params[4], wires=wires[2]) qml.CRY(params[5], wires=[wires[2], wires[1]]) qml.CRZ(params[5], wires=[wires[0], wires[3]]).inv() qml.PhaseShift(params[6], wires=wires[0]).inv() qml.Rot(params[6], params[7], params[8], wires=wires[0]) # # qml.Rot(params[8], params[8], params[9], wires=wires[1]).inv() qml.MultiRZ(params[11], wires=[wires[0], wires[1]]) # # qml.PauliRot(params[12], "XXYZ", wires=[wires[0], wires[1], wires[2], wires[3]]) qml.CPhase(params[12], wires=[wires[3], wires[2]]) qml.IsingXX(params[13], wires=[wires[1], wires[0]]) qml.IsingXY(params[14], wires=[wires[3], wires[2]]) qml.IsingYY(params[14], wires=[wires[3], wires[2]]) qml.IsingZZ(params[14], wires=[wires[2], wires[1]]) qml.U1(params[15], wires=wires[0]) qml.U2(params[16], params[17], wires=wires[0]) qml.U3(params[18], params[19], params[20], wires=wires[1]) # # qml.CRot(params[21], params[22], params[23], wires=[wires[1], wires[2]]).inv() # expected tofail qml.SingleExcitation(params[24], wires=[wires[2], wires[0]]) qml.DoubleExcitation(params[25], wires=[wires[2], wires[0], wires[1], wires[3]]) qml.SingleExcitationPlus(params[26], wires=[wires[0], wires[2]]) qml.SingleExcitationMinus(params[27], wires=[wires[0], wires[2]]) qml.DoubleExcitationPlus(params[27], wires=[wires[2], wires[0], wires[1], wires[3]]) qml.DoubleExcitationMinus(params[27], wires=[wires[2], wires[0], wires[1], wires[3]]) qml.RX(params[28], wires=wires[0]) qml.RX(params[29], wires=wires[1])
"ControlledQubitUnitary": qml.ControlledQubitUnitary(np.eye(2), control_wires=[1], wires=[0]), "MultiControlledX": qml.MultiControlledX(control_wires=[1, 2], wires=[0]), "RX": qml.RX(0, wires=[0]), "RY": qml.RY(0, wires=[0]), "RZ": qml.RZ(0, wires=[0]), "Rot": qml.Rot(0, 0, 0, wires=[0]), "S": qml.S(wires=[0]), "SWAP": qml.SWAP(wires=[0, 1]), "ISWAP": qml.ISWAP(wires=[0, 1]), "T": qml.T(wires=[0]), "SX": qml.SX(wires=[0]), "Toffoli": qml.Toffoli(wires=[0, 1, 2]), "QFT": qml.templates.QFT(wires=[0, 1, 2]), "IsingXX": qml.IsingXX(0, wires=[0, 1]), "IsingYY": qml.IsingYY(0, wires=[0, 1]), "IsingZZ": qml.IsingZZ(0, wires=[0, 1]), "SingleExcitation": qml.SingleExcitation(0, wires=[0, 1]), "SingleExcitationPlus": qml.SingleExcitationPlus(0, wires=[0, 1]), "SingleExcitationMinus": qml.SingleExcitationMinus(0, wires=[0, 1]), "DoubleExcitation": qml.DoubleExcitation(0, wires=[0, 1, 2, 3]), "DoubleExcitationPlus": qml.DoubleExcitationPlus(0, wires=[0, 1, 2, 3]), "DoubleExcitationMinus": qml.DoubleExcitationMinus(0, wires=[0, 1, 2, 3]), "QubitCarry": qml.QubitCarry(wires=[0, 1, 2, 3]), "QubitSum": qml.QubitSum(wires=[0, 1, 2]), "PauliRot": qml.PauliRot(0, "XXYY", wires=[0, 1, 2, 3]), "U1": qml.U1(0, wires=0), "U2": qml.U2(0, 0, wires=0), "U3": qml.U3(0, 0, 0, wires=0), "SISWAP": qml.SISWAP(wires=[0, 1]), }