def test_invalid_inputs_tape(self, permutation_order, expected_error_message): """Tests if errors are thrown for invalid permutations with tapes.""" wire_labels = [0, 2, "a", "c", 1] with qml.tape.QuantumTape() as tape: with pytest.raises(ValueError, match=expected_error_message): qml.Permute(permutation_order, wires=wire_labels)
def test_identity_permutation_tape(self): """Test that identity permutations have no effect on tapes.""" with qml.tape.QuantumTape() as tape: qml.Permute([0, "a", "c", "d"], wires=[0, "a", "c", "d"]) # expand the Permute operation tape = tape.expand() assert len(tape.operations) == 0
def test_two_cycle_permutations_tape(self, permutation_order, wire_order, expected_wires): """Test some two-cycles on tapes.""" with qml.tape.QuantumTape() as tape: qml.Permute(permutation_order, wire_order) # expand the Permute operation tape = tape.expand() # Ensure all operations are SWAPs, and that the wires are the same assert all(op.name == "SWAP" for op in tape.operations) assert [op.wires.labels for op in tape.operations] == expected_wires
def test_subset_permutations_tape(self, wire_labels, permutation_order, wire_subset, expected_wires): """Test permutation of wire subsets on tapes.""" with qml.tape.QuantumTape() as tape: # Make sure all the wires are actually there for wire in wire_labels: qml.RZ(0, wires=wire) qml.Permute(permutation_order, wire_subset) # expand the Permute operation tape = tape.expand() # Make sure to start comparison after the set of RZs have been applied assert all(op.name == "SWAP" for op in tape.operations[len(wire_labels):]) assert [op.wires.labels for op in tape.operations[len(wire_labels):]] == expected_wires
# two wire labels, so CRX is third text object assert ax.texts[2].get_text() == "RX\n(1.23)" plt.close() general_op_data = [ qml.RX(1.234, wires=0), qml.Hadamard(0), qml.S(wires=0), qml.IsingXX(1.234, wires=(0, 1)), qml.U3(1.234, 2.345, 3.456, wires=0), # State Prep qml.BasisState([0, 1, 0], wires=(0, 1, 2)), ### Templates qml.QFT(wires=range(3)), qml.Permute([4, 2, 0, 1, 3], wires=(0, 1, 2, 3, 4)), qml.GroverOperator(wires=(0, 1, 2, 3, 4, 5)), ### Continuous Variable qml.Kerr(1.234, wires=0), qml.Beamsplitter(1.234, 2.345, wires=(0, 1)), qml.Rotation(1.234, wires=0), ] class TestGeneralOperations: """Tests general operations.""" width = 0.75 - 2 * 0.2 @pytest.mark.parametrize("op", general_op_data) def test_general_operations(self, op):
def two_cycle(): qml.Permute(permutation_order, wires=dev.wires) return qml.expval(qml.PauliZ(0))
def test_id(self): """Tests that the id attribute can be set.""" template = qml.Permute([0, 1, 2], wires=[0, 1, 2], id="a") assert template.id == "a"
def permute_qubits(): qml.Permute(permutation_order, wires=dev.wires) return qml.expval(qml.PauliZ(0))
def circuit2(): qml.Permute(permutation2, wires=["z", "a", "k", "o"]) return qml.expval(qml.Identity("z"))
def circuit(): qml.Permute(permutation, wires=range(4)) return qml.expval(qml.Identity(0))
def identity_permutation(): qml.Permute([0, 1, 2, 3], wires=dev.wires) return qml.expval(qml.PauliZ(0))
def subset_perm(): qml.Permute(permutation_order, wires=wire_subset) return qml.expval(qml.PauliZ(0))
def arbitrary_perm(): qml.Permute(permutation_order, wires=dev.wires) return qml.expval(qml.PauliZ(0))