Skip to content

Commit

Permalink
check if benchmark is called only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
boucherlfg committed Feb 1, 2025
1 parent 770119f commit 47c7939
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/test_readout_noise_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import pytest
from unittest.mock import patch
import numpy as np

class MP:
def __init__(self, wire):
self.wires = [wire]

class Shots:
def __init__(self, shots):
self.total_shots = shots
Expand All @@ -11,6 +16,7 @@ class Tape:
def __init__(self, wires, shots):
self.wires = wires
self.shots = Shots(shots)
self.measurements = [MP(wire) for wire in wires]

@pytest.fixture
def mock_readout_noise_matrices():
Expand Down Expand Up @@ -40,8 +46,13 @@ def test_execute(mock_readout_noise_matrices):
expected = {
"000" : 0, "001" : 0, "010" : 0, "011" : 0, "100" : 500, "101" : 0, "110" : 500, "111" : 0
}

step = rns.ReadoutNoiseSimulation(False)
_ = step.execute(tape, results)
mock_readout_noise_matrices.assert_not_called()

step = rns.ReadoutNoiseSimulation(True)

results = step.execute(tape, results)
result2 = step.execute(tape, results)
mock_readout_noise_matrices.assert_called_once()

assert all(v1 == v2 for v1, v2 in zip(expected.values(), results.values()))
assert all(v1 == v2 for v1, v2 in zip(expected.values(), result2.values()))

0 comments on commit 47c7939

Please sign in to comment.