Skip to content

Commit

Permalink
utils => mcm_utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr committed Jun 3, 2024
1 parent d2c9459 commit 646a626
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions tests/devices/default_qubit/test_default_qubit_native_mcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"""Tests for default qubit preprocessing."""
from typing import Sequence

import mcm_utils
import numpy as np
import pytest
import utils

import pennylane as qml
from pennylane.devices.qubit.apply_operation import MidMeasureMP, apply_mid_measure
Expand Down Expand Up @@ -123,7 +123,7 @@ def func(x, y):
results1 = func1(*params)
results2 = func2(*params)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


# pylint: disable=unused-argument
Expand Down Expand Up @@ -171,7 +171,7 @@ def func(x, y, z):
results1 = func1(*params)
results2 = func2(*params)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("postselect", [None, 0, 1])
Expand All @@ -195,7 +195,7 @@ def func(x, y, z):
results2 = func2(*params)

for measure_f, res1, res2 in zip([qml.counts, qml.expval], results1, results2):
utils.validate_measurements(measure_f, 5000, res1, res2)
mcm_utils.validate_measurements(measure_f, 5000, res1, res2)


@pytest.mark.parametrize("shots", [None, 3000, [3000, 3001]])
Expand Down Expand Up @@ -226,7 +226,7 @@ def func(x, y):
results1 = func1(*params)
results2 = func2(*params)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("postselect", [None, 0, 1])
Expand Down Expand Up @@ -255,11 +255,11 @@ def func(x, y, z):
if isinstance(shots, Sequence):
for s, r1, r2 in zip(shots, results1, results2):
for _r1, _r2 in zip(r1, r2):
utils.validate_measurements(measure_f, s, _r1, _r2)
mcm_utils.validate_measurements(measure_f, s, _r1, _r2)
return

for r1, r2 in zip(results1, results2):
utils.validate_measurements(measure_f, shots, r1, r2)
mcm_utils.validate_measurements(measure_f, shots, r1, r2)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -299,7 +299,7 @@ def func(x):
results1 = func1(param)
results2 = func2(param)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("shots", [None, 5000, [5000, 5001]])
Expand Down Expand Up @@ -341,7 +341,7 @@ def func(x):
results1 = func1(param)
results2 = func2(param)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("shots", [None, 5000, [5000, 5001]])
Expand Down Expand Up @@ -372,7 +372,7 @@ def func(x, y, z):
results1 = func1(*params)
results2 = func2(*params)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("shots", [7500, [5000, 5001]])
Expand Down Expand Up @@ -403,7 +403,7 @@ def func(x):
results1 = func1(param)
results2 = func2(param)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)


@pytest.mark.parametrize("shots", [5000])
Expand Down Expand Up @@ -435,7 +435,7 @@ def func(x, y):
results1 = func1(*param)
results2 = func2(*param)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)

grad1 = qml.grad(func)(*param)
grad2 = qml.grad(func2)(*param)
Expand Down Expand Up @@ -467,7 +467,7 @@ def func(x, y):
results1 = func1(*param)
results2 = func2(*param)

utils.validate_measurements(measure_fn, shots, results1, results2, batch_size=2)
mcm_utils.validate_measurements(measure_fn, shots, results1, results2, batch_size=2)

if measure_fn is qml.sample and postselect is None:
for i in range(2): # batch_size
Expand Down Expand Up @@ -524,7 +524,7 @@ def func(x, y):
results1 = func1(*param)
results2 = func2(*param)

utils.validate_measurements(qml.sample, shots, results1, results2, batch_size=None)
mcm_utils.validate_measurements(qml.sample, shots, results1, results2, batch_size=None)

evals = obs.eigvals()
for eig in evals:
Expand Down Expand Up @@ -688,4 +688,4 @@ def func(x):
results1 = func1(param)
results2 = func2(param)

utils.validate_measurements(measure_f, shots, results1, results2)
mcm_utils.validate_measurements(measure_f, shots, results1, results2)
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# pylint: disable=import-outside-toplevel
from unittest.mock import patch

import mcm_utils
import numpy as np
import pytest
import utils

import pennylane as qml
from pennylane import numpy as np
Expand Down Expand Up @@ -810,4 +810,4 @@ def ansatz():
if measure_f == qml.sample:
results0 = results0[results0 != fill_in_value]
results1 = results1[results1 != fill_in_value]
utils.validate_measurements(measure_f, shots, results1, results0)
mcm_utils.validate_measurements(measure_f, shots, results1, results0)

0 comments on commit 646a626

Please sign in to comment.