Skip to content

Commit

Permalink
add missing raise test
Browse files Browse the repository at this point in the history
  • Loading branch information
obliviateandsurrender committed Oct 11, 2023
1 parent 4cb4683 commit 4507dbc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/transforms/test_qcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -5594,3 +5594,28 @@ def block(weights, wires):

# each frag should have the device size constraint satisfied.
assert all(len(set(e[2] for e in f.edges.data("wire"))) <= device_size for f in frags)

def test_raise_with_hamiltonian(self):
"""Test that exception is correctly raise when caclulating expectation values of multiple Hamiltonians"""

dev_cut = qml.device("default.qubit", wires=4)

hamiltonian = qml.Hamiltonian(
[1.0, 1.0],
[qml.PauliZ(1) @ qml.PauliZ(2) @ qml.PauliZ(3), qml.PauliY(0) @ qml.PauliX(1)],
)

def f():
qml.CNOT(wires=[0, 1])
qml.WireCut(wires=0)
qml.RX(1.0, wires=0)
qml.CNOT(wires=[0, 1])

return [qml.expval(hamiltonian), qml.expval(hamiltonian)]

with pytest.raises(
NotImplementedError,
match="Hamiltonian expansion is supported only with a single Hamiltonian",
):
cut_circuit = qcut.cut_circuit(qml.QNode(f, dev_cut))
cut_circuit()

0 comments on commit 4507dbc

Please sign in to comment.