Skip to content

Commit e0d0846

Browse files
Jaybsonisoranjh
andauthored
Fix warnings in estimator tests (#8523)
**Context:** Cleaning up the warnings that were raised by pytest. **Description of the Change:** - Remove `np.matrix` dependance in the `FirstQuantization` class. - Renamed some dummy classes created in the `test_estimate.py` file. - Fix a test for the `PauliRot` resource operator which was previously skipped. --------- Co-authored-by: soranjh <[email protected]>
1 parent 8f7f071 commit e0d0846

File tree

4 files changed

+76
-72
lines changed

4 files changed

+76
-72
lines changed

doc/releases/changelog-dev.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
[(#8486)](https://github.com/PennyLaneAI/pennylane/pull/8486)
169169
[(#8495)](https://github.com/PennyLaneAI/pennylane/pull/8495)
170170

171+
* The various private functions of the :class:`~pennylane.estimator.FirstQuantization` class have
172+
been modified to avoid using `numpy.matrix` as this function is deprecated.
173+
[(#8523)](https://github.com/PennyLaneAI/pennylane/pull/8523)
174+
171175
* The `ftqc` module now includes dummy transforms for several Catalyst/MLIR passes (`to-ppr`, `commute-ppr`, `merge-ppr-ppm`, `pprm-to-mbqc`
172176
and `reduce-t-depth`), to allow them to be captured as primitives in PLxPR and mapped to the MLIR passes in Catalyst. This enables using the passes with the unified compiler and program capture.
173177
[(#8519)](https://github.com/PennyLaneAI/pennylane/pull/8519)
@@ -178,6 +182,7 @@
178182
:class:`~.TemporaryAND`, :class:`~.QSVT`, and :class:`~.SelectPauliRot`.
179183
[(#8490)](https://github.com/PennyLaneAI/pennylane/pull/8490)
180184

185+
181186
<h3>Documentation 📝</h3>
182187

183188
<h3>Bug fixes 🐛</h3>

pennylane/estimator/qpe_resources/first_quantization.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(
120120
/ self.omega
121121
* np.array([np.cross(vectors[i], vectors[j]) for i, j in [(1, 2), (2, 0), (0, 1)]])
122122
)
123-
bbt = np.matrix(recip_vectors) @ np.matrix(recip_vectors).T
123+
bbt = recip_vectors @ recip_vectors.T
124124
self.cubic = np.linalg.norm(bbt - (recip_vectors**2).max() * np.identity(3)) < 1e-6
125125

126126
self._lamb = self.norm(
@@ -731,7 +731,7 @@ def _norm_noncubic(
731731
* np.array([np.cross(vectors[i], vectors[j]) for i, j in [(1, 2), (2, 0), (0, 1)]])
732732
)
733733

734-
bbt = np.matrix(recip_vectors) @ np.matrix(recip_vectors).T
734+
bbt = recip_vectors @ recip_vectors.T
735735

736736
orthogonal = (
737737
np.linalg.norm(bbt - np.array([np.max(b**2) for b in recip_vectors]) * np.identity(3))
@@ -801,8 +801,7 @@ def _norm_noncubic(
801801
lambda_u_1 = lambda_u * lambda_nu_1 / lambda_nu
802802
lambda_v_1 = lambda_v * lambda_nu_1 / lambda_nu
803803

804-
b_mat = np.matrix(recip_vectors)
805-
abs_sum = np.abs(b_mat @ b_mat.T).flatten().sum()
804+
abs_sum = np.abs(recip_vectors @ recip_vectors.T).flatten().sum()
806805

807806
# taken from Appendix I.1 of arXiv:2302.07981v1 (2023)
808807
if orthogonal:
@@ -918,7 +917,7 @@ def _qubit_cost_noncubic(n, eta, error, br, charge, vectors):
918917
* np.pi
919918
* eta
920919
* 2 ** (2 * n_p - 2)
921-
* np.abs(np.matrix(recip_vectors) @ np.matrix(recip_vectors).T).flatten().sum()
920+
* np.abs(recip_vectors @ recip_vectors.T).flatten().sum()
922921
/ error_b
923922
)
924923
)
@@ -1013,7 +1012,7 @@ def _unitary_cost_noncubic(n, eta, error, br, charge, vectors):
10131012
* np.pi
10141013
* eta
10151014
* 2 ** (2 * n_p - 2)
1016-
* np.abs(np.matrix(recip_vectors) @ np.matrix(recip_vectors).T).flatten().sum()
1015+
* np.abs(recip_vectors @ recip_vectors.T).flatten().sum()
10171016
/ error_b
10181017
)
10191018
)

tests/estimator/ops/test_estimator_parametric_multi_qubit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_resource_rep(self, pauli_string, precision):
187187

188188
expected_h_count = (0, 4, 6, 6, 0)
189189
expected_s_count = (0, 1, 0, 1, 0)
190-
params = zip(pauli_words, expected_h_count, expected_s_count)
190+
params = tuple(zip(pauli_words, expected_h_count, expected_s_count))
191191

192192
@pytest.mark.parametrize("precision", (None, 1e-3))
193193
@pytest.mark.parametrize("pauli_string, expected_h_count, expected_s_count", params)
@@ -225,16 +225,13 @@ def test_resources_empty_pauli_string(self):
225225
@pytest.mark.parametrize("pauli_string, expected_h_count, expected_s_count", params)
226226
def test_resources_from_rep(self, pauli_string, expected_h_count, expected_s_count):
227227
"""Test that the resources can be computed from the compressed representation and params."""
228-
op = qre.PauliRot(0.5, pauli_string, wires=range(len(pauli_string)))
228+
op = qre.PauliRot(pauli_string, 0.5, wires=range(len(pauli_string)))
229229
active_wires = len(pauli_string.replace("I", ""))
230230

231231
if set(pauli_string) == {"I"}:
232232
expected = [qre.GateCount(qre.GlobalPhase.resource_rep())]
233233
else:
234-
expected = [
235-
qre.GateCount(qre.RZ.resource_rep()),
236-
qre.GateCount(qre.CNOT.resource_rep(), 2 * (active_wires - 1)),
237-
]
234+
expected = []
238235

239236
if expected_h_count:
240237
expected.append(qre.GateCount(qre.Hadamard.resource_rep(), expected_h_count))
@@ -248,6 +245,9 @@ def test_resources_from_rep(self, pauli_string, expected_h_count, expected_s_cou
248245
)
249246
)
250247

248+
expected.append(qre.GateCount(qre.RZ.resource_rep(precision=0.5)))
249+
expected.append(qre.GateCount(qre.CNOT.resource_rep(), 2 * (active_wires - 1)))
250+
251251
op_compressed_rep = op.resource_rep_from_op()
252252
op_resource_type = op_compressed_rep.op_type
253253
op_resource_params = op_compressed_rep.params

0 commit comments

Comments
 (0)