Example #1
0
        def qfunc():
            qml.Hadamard(wires=0)
            qml.Barrier(only_visual=True, wires=0)
            qml.Barrier(wires=0)
            qml.Hadamard(wires=0)

            return qml.expval(qml.PauliZ(0))
Example #2
0
        def qfunc():

            qml.Hadamard(wires=0)
            qml.Barrier(wires=0)
            qml.Barrier(wires=0)
            qml.Hadamard(wires=0)

            return qml.expval(qml.PauliZ(0))
    def test_barrier_only_visual(self):
        """Test the barrier is always drawn"""

        ops = [
            qml.PauliX(0),
            qml.Barrier(wires=0),
            qml.Barrier(only_visual=True, wires=0),
            qml.PauliX(0),
        ]
        layers = drawable_layers(ops)
        assert layers == [{ops[0]}, {ops[1]}, {ops[2]}, {ops[3]}]
Example #4
0
    def test_Barrier(self):
        """Test Barrier gets correct special call."""

        with QuantumTape() as tape:
            qml.Barrier(wires=(0, 1, 2))

        _, ax = tape_mpl(tape)
        layer = 0

        assert len(ax.lines) == 3
        assert len(ax.collections) == 2

        plt.close()
    def test_barrier_block(self):
        """Test the barrier blocking operators"""

        ops = [qml.PauliX(0), qml.Barrier(wires=[0, 1]), qml.PauliX(1)]
        layers = drawable_layers(ops)
        assert layers == [{ops[0]}, {ops[1]}, {ops[2]}]
Example #6
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]),
 "Barrier":
 qml.Barrier(wires=[0, 1, 2]),
 "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":
Example #7
0
 def barrier():
     qml.PauliX(wires=0)
     qml.Barrier(wires=[0, 1])
     qml.CNOT(wires=[0, 1])
Example #8
0
    (qml.PauliY(0), "Y", "Y"),
    (qml.PauliZ(0), "Z", "Z"),
    (qml.S(wires=0), "S", "S⁻¹"),
    (qml.T(wires=0), "T", "T⁻¹"),
    (qml.SX(wires=0), "SX", "SX⁻¹"),
    (qml.CNOT(wires=(0, 1)), "⊕", "⊕"),
    (qml.CZ(wires=(0, 1)), "Z", "Z"),
    (qml.CY(wires=(0, 1)), "Y", "Y"),
    (qml.SWAP(wires=(0, 1)), "SWAP", "SWAP⁻¹"),
    (qml.ISWAP(wires=(0, 1)), "ISWAP", "ISWAP⁻¹"),
    (qml.SISWAP(wires=(0, 1)), "SISWAP", "SISWAP⁻¹"),
    (qml.SQISW(wires=(0, 1)), "SISWAP", "SISWAP⁻¹"),
    (qml.CSWAP(wires=(0, 1, 2)), "SWAP", "SWAP"),
    (qml.Toffoli(wires=(0, 1, 2)), "⊕", "⊕"),
    (qml.MultiControlledX(control_wires=(0, 1, 2), wires=(3)), "⊕", "⊕"),
    (qml.Barrier(0), "||", "||"),
    (qml.WireCut(wires=0), "//", "//"),
]


@pytest.mark.parametrize("op, label1, label2", label_data)
def test_label_method(op, label1, label2):
    assert op.label() == label1
    assert op.label(decimals=2) == label1

    op.inv()
    assert op.label() == label2


control_data = [
    (qml.Identity(0), Wires([])),