Skip to content

Commit 59c6cd5

Browse files
authored
Fix flamingpy build and CI (#127)
* add panda to dev requirements * fix some tests * run black * backwards-compatible sparse check * fix missed test and RTD * changelog * add name to contribution * undo xfail
1 parent 282e7df commit 59c6cd5

File tree

11 files changed

+26
-20
lines changed

11 files changed

+26
-20
lines changed

.github/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* An instance of a depracated `fig.gca` with a keyword argument was fixed. [#124](https://github.com/XanaduAI/flamingpy/pull/124)
99
* Remove the tight layout setting from `draw_EGraph_matplotlib`, which was causing a warning. [#125](https://github.com/XanaduAI/flamingpy/pull/125)
1010
* Bump tj-actions/branch-names from 5 to 8 to fix vulnerability. [#126](https://github.com/XanaduAI/flamingpy/pull/126)
11+
* Apply minor tweaks to source code and tests to update compatibility across Python versions. [#127](https://github.com/XanaduAI/flamingpy/pull/127)
1112

1213
### Improvements
1314

@@ -21,7 +22,7 @@
2122

2223
This release contains contributions from (in alphabetical order):
2324

24-
Nariman Saadatmand
25+
Nariman Saadatmand, [Matthew Silverman](https://github.com/timmysilv)
2526

2627
See full commit details ...
2728

.readthedocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ python:
1919
- requirements: doc/dev_requirements.txt
2020
- method: setuptools
2121
path: .
22-
system_packages: true

dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ scipy>=1.6
1515
thewalrus>=0.19.0
1616
plotly>=4.5.0
1717
pylint==2.13.5
18+
pandas>=2.0

doc/tutorials/run_error_correction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
====================================
55
"""
66

7-
87
######################################################################
98
# *Author: Ilan Tzitrin*
109
#

doc/tutorials/run_graph_states.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
============
55
"""
66

7-
87
######################################################################
98
# *Authors: Ilan Tzitrin and Luis Mantilla*
109
#

flamingpy/cv/ops.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def invert_permutation(p):
2828
return p_inverted
2929

3030

31+
def issparse(array):
32+
"""Check if an array is sparse. Backwards-compatible with old SciPy versions."""
33+
return isinstance(array, getattr(sp, "sparray", sp.coo_matrix))
34+
35+
3136
def SCZ_mat(adj, sparse=True):
3237
"""Return a symplectic matrix corresponding to CZ gate application.
3338
@@ -59,7 +64,7 @@ def SCZ_mat(adj, sparse=True):
5964
# Construct symplectic
6065
symplectic = block_func([[identity, zeros], [adj, identity]])
6166

62-
if not sparse and isinstance(symplectic, sp.coo_matrix):
67+
if not sparse and issparse(symplectic):
6368
return symplectic.toarray()
6469

6570
return symplectic

flamingpy/decoders/unionfind/algos.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ def initialize_cluster_trees(stabilizer_graph):
108108
root_stabilizer = erasure_graph_nodes[component.pop()]
109109
cluster_root = Root(
110110
node_dict[root_stabilizer],
111-
parity=root_stabilizer.parity
112-
if isinstance(root_stabilizer, Stabilizer)
113-
else "boundary",
111+
parity=(
112+
root_stabilizer.parity if isinstance(root_stabilizer, Stabilizer) else "boundary"
113+
),
114114
) # boundary nodes are represented by tuples
115115
for vertex in component:
116116
vertex_stabilizer = erasure_graph_nodes[vertex]
117117
union(
118118
cluster_root,
119119
Root(
120120
node_dict[vertex_stabilizer],
121-
parity=vertex_stabilizer.parity
122-
if isinstance(vertex_stabilizer, Stabilizer)
123-
else "boundary",
121+
parity=(
122+
vertex_stabilizer.parity
123+
if isinstance(vertex_stabilizer, Stabilizer)
124+
else "boundary"
125+
),
124126
),
125127
)
126128
if cluster_root.parity:

flamingpy/examples/lc_equivalence.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example for testing LC equivalence of graph states."""
2+
23
from flamingpy.utils.graph_states import star_graph, complete_graph, linear_cluster, ring_graph
34

45
print("Testing LC equivalence of graph states:", "\n")

flamingpy/simulations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
try:
3131
import mpi4py.rc
3232

33-
mpi4py.rc.threaded = False
33+
mpi4py.rc.threads = False
3434
from mpi4py import MPI
3535
except ImportError: # pragma: no cover
3636
warnings.warn("Failed to import mpi4py libraries.", ImportWarning)

tests/cv/test_cv_ops.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import scipy.sparse as sp
2626

2727
from flamingpy.codes.graphs import EGraph
28-
from flamingpy.cv.ops import invert_permutation, SCZ_mat, SCZ_apply
28+
from flamingpy.cv.ops import invert_permutation, SCZ_mat, SCZ_apply, issparse
2929

3030
now = datetime.now()
3131
int_time = int(str(now.year) + str(now.month) + str(now.day) + str(now.hour) + str(now.minute))
@@ -50,13 +50,11 @@ def random_graph(request):
5050
class TestSCZ:
5151
"""Tests for symplectic CZ matrices."""
5252

53-
@pytest.mark.parametrize(
54-
"sparse, expected_out_type", sorted([(True, sp.coo_matrix), (False, np.ndarray)])
55-
)
56-
def test_SCZ_mat_sparse_param(self, random_graph, sparse, expected_out_type):
53+
@pytest.mark.parametrize("sparse", [True, False])
54+
def test_SCZ_mat_sparse_param(self, random_graph, sparse):
5755
"""Tests the SCZ_mat function outputs sparse or dense arrays."""
5856
SCZ = SCZ_mat(random_graph[2], sparse=sparse)
59-
assert isinstance(SCZ, expected_out_type)
57+
assert issparse(SCZ) if sparse else isinstance(SCZ, np.ndarray)
6058

6159
def test_SCZ_mat(self, random_graph):
6260
"""Tests the SCZ_mat function."""
@@ -65,7 +63,7 @@ def test_SCZ_mat(self, random_graph):
6563
# Check if SCZ_mat adjusts type of output matrix based on
6664
# type of input.
6765
assert isinstance(SCZ, np.ndarray)
68-
assert isinstance(SCZ_sparse, sp.coo_matrix)
66+
assert issparse(SCZ_sparse)
6967
# Check that structure of SCZ matrix is correct.
7068
for mat in (SCZ, SCZ_sparse.toarray()):
7169
assert np.array_equal(mat[:N, :N], np.identity(N))

tests/examples/test_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# pylint: disable=import-outside-toplevel,unused-import
1818

1919
import pytest
20+
import numpy as np
2021
from flamingpy.codes import alternating_polarity
2122

2223

@@ -31,7 +32,7 @@ def test_decoder_example(noise, decoder):
3132
ec = "primal"
3233

3334
result = decode_surface_code(distance, boundaries, ec, noise, decoder, draw=True)
34-
assert result.__class__.__name__ == "bool_"
35+
assert isinstance(result, np.bool_)
3536

3637

3738
def test_gkp_example():

0 commit comments

Comments
 (0)