From 4507dbc11f184e81d6b1166d946676465d644290 Mon Sep 17 00:00:00 2001 From: obliviateandsurrender Date: Wed, 11 Oct 2023 01:15:11 -0400 Subject: [PATCH] add missing `raise` test --- tests/transforms/test_qcut.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/transforms/test_qcut.py b/tests/transforms/test_qcut.py index 7c4b3d3bcaf..7c96c26d54b 100644 --- a/tests/transforms/test_qcut.py +++ b/tests/transforms/test_qcut.py @@ -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()