From d63e9b1e40e3d48a69239c97a4a96205c23cfd89 Mon Sep 17 00:00:00 2001 From: Roland Guichard Date: Wed, 1 Nov 2023 10:35:45 +0000 Subject: [PATCH] First attempt to test readout errors with tomography. --- tests/qadence/test_error_models.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/qadence/test_error_models.py b/tests/qadence/test_error_models.py index e7c753e0..1c26221f 100644 --- a/tests/qadence/test_error_models.py +++ b/tests/qadence/test_error_models.py @@ -15,12 +15,15 @@ from qadence.constructors import ( total_magnetization, ) +from qadence.constructors.hamiltonians import hamiltonian_factory from qadence.errors import Errors +from qadence.measurements.protocols import Measurements from qadence.models import QuantumModel from qadence.operations import ( CNOT, RX, RZ, + H, HamEvo, X, Y, @@ -118,3 +121,36 @@ def test_readout_error_backends(backend: BackendName) -> None: for bitstring, count in noisy_samples[0].items() ] ) + + +@pytest.mark.parametrize( + "block, observable, backend", + [ + (kron(H(0), Z(1)), hamiltonian_factory(2, detuning=Z), BackendName.PYQTORCH), + # (kron(Z(0), Z(1), Z(2)) + kron(X(0), Y(1), Z(2)), BackendName.PYQTORCH), + # (add(Z(0), Z(1), Z(2)), BackendName.PYQTORCH), + # ( + # HamEvo( + # generator=kron(X(0), X(1)) + kron(Z(0), Z(1)) + kron(X(2), X(3)), parameter=0.005 + # ), + # BackendName.PYQTORCH, + # ), + # (add(Z(0), Z(1), kron(X(2), X(3))) + add(X(2), X(3)), BackendName.PYQTORCH), + # (dd(kron(Z(0), Z(1)), kron(X(2), X(3))), BackendName.PYQTORCH), + # (total_magnetization(4), BackendName.PYQTORCH), + # (kron(Z(0), Z(1)) + CNOT(0, 1), BackendName.PYQTORCH), + ], +) +def test_readout_error_with_measurements( + block: AbstractBlock, observable: AbstractBlock, backend: BackendName +): + circuit = QuantumCircuit(block.n_qubits, block) + model = QuantumModel(circuit=circuit, observable=observable, backend=backend) + + error = Errors(protocol=Errors.READOUT) + measurement = Measurements(protocol=Measurements.TOMOGRAPHY, options={"n_shots": 1000}) + + measured = model.expectation(measurement=measurement) + noisy = model.expectation(measurement=measurement, error=error) + exact = model.expectation() + print(f"noisy {noisy} exact {exact}")