Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flamingpy build and CI #127

Merged
merged 8 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* An instance of a depracated `fig.gca` with a keyword argument was fixed. [#124](https://github.com/XanaduAI/flamingpy/pull/124)
* Remove the tight layout setting from `draw_EGraph_matplotlib`, which was causing a warning. [#125](https://github.com/XanaduAI/flamingpy/pull/125)
* Bump tj-actions/branch-names from 5 to 8 to fix vulnerability. [#126](https://github.com/XanaduAI/flamingpy/pull/126)
* Apply minor tweaks to source code and tests to update compatibility across Python versions. [#127](https://github.com/XanaduAI/flamingpy/pull/127)

### Improvements

Expand All @@ -21,7 +22,7 @@

This release contains contributions from (in alphabetical order):

Nariman Saadatmand
Nariman Saadatmand, [Matthew Silverman](https://github.com/timmysilv)

See full commit details ...

Expand Down
1 change: 0 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ python:
- requirements: doc/dev_requirements.txt
- method: setuptools
path: .
system_packages: true
ilan-tz marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ scipy>=1.6
thewalrus>=0.19.0
plotly>=4.5.0
pylint==2.13.5
pandas>=2.0
ilan-tz marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion doc/tutorials/run_error_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
====================================
"""


######################################################################
# *Author: Ilan Tzitrin*
#
Expand Down
1 change: 0 additions & 1 deletion doc/tutorials/run_graph_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
============
"""


######################################################################
# *Authors: Ilan Tzitrin and Luis Mantilla*
#
Expand Down
7 changes: 6 additions & 1 deletion flamingpy/cv/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def invert_permutation(p):
return p_inverted


def issparse(array):
"""Check if an array is sparse. Backwards-compatible with old SciPy versions."""
return isinstance(array, getattr(sp, "sparray", sp.coo_matrix))
ilan-tz marked this conversation as resolved.
Show resolved Hide resolved


def SCZ_mat(adj, sparse=True):
"""Return a symplectic matrix corresponding to CZ gate application.

Expand Down Expand Up @@ -59,7 +64,7 @@ def SCZ_mat(adj, sparse=True):
# Construct symplectic
symplectic = block_func([[identity, zeros], [adj, identity]])

if not sparse and isinstance(symplectic, sp.coo_matrix):
if not sparse and issparse(symplectic):
return symplectic.toarray()

return symplectic
Expand Down
14 changes: 8 additions & 6 deletions flamingpy/decoders/unionfind/algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@ def initialize_cluster_trees(stabilizer_graph):
root_stabilizer = erasure_graph_nodes[component.pop()]
cluster_root = Root(
node_dict[root_stabilizer],
parity=root_stabilizer.parity
if isinstance(root_stabilizer, Stabilizer)
else "boundary",
parity=(
root_stabilizer.parity if isinstance(root_stabilizer, Stabilizer) else "boundary"
),
) # boundary nodes are represented by tuples
for vertex in component:
vertex_stabilizer = erasure_graph_nodes[vertex]
union(
cluster_root,
Root(
node_dict[vertex_stabilizer],
parity=vertex_stabilizer.parity
if isinstance(vertex_stabilizer, Stabilizer)
else "boundary",
parity=(
vertex_stabilizer.parity
if isinstance(vertex_stabilizer, Stabilizer)
else "boundary"
),
),
)
if cluster_root.parity:
Expand Down
1 change: 1 addition & 0 deletions flamingpy/examples/lc_equivalence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example for testing LC equivalence of graph states."""

from flamingpy.utils.graph_states import star_graph, complete_graph, linear_cluster, ring_graph

print("Testing LC equivalence of graph states:", "\n")
Expand Down
2 changes: 1 addition & 1 deletion flamingpy/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
try:
import mpi4py.rc

mpi4py.rc.threaded = False
mpi4py.rc.threads = False
from mpi4py import MPI
except ImportError: # pragma: no cover
warnings.warn("Failed to import mpi4py libraries.", ImportWarning)
Expand Down
12 changes: 5 additions & 7 deletions tests/cv/test_cv_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import scipy.sparse as sp

from flamingpy.codes.graphs import EGraph
from flamingpy.cv.ops import invert_permutation, SCZ_mat, SCZ_apply
from flamingpy.cv.ops import invert_permutation, SCZ_mat, SCZ_apply, issparse

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

@pytest.mark.parametrize(
"sparse, expected_out_type", sorted([(True, sp.coo_matrix), (False, np.ndarray)])
)
def test_SCZ_mat_sparse_param(self, random_graph, sparse, expected_out_type):
@pytest.mark.parametrize("sparse", [True, False])
def test_SCZ_mat_sparse_param(self, random_graph, sparse):
"""Tests the SCZ_mat function outputs sparse or dense arrays."""
SCZ = SCZ_mat(random_graph[2], sparse=sparse)
assert isinstance(SCZ, expected_out_type)
assert issparse(SCZ) if sparse else isinstance(SCZ, np.ndarray)

def test_SCZ_mat(self, random_graph):
"""Tests the SCZ_mat function."""
Expand All @@ -65,7 +63,7 @@ def test_SCZ_mat(self, random_graph):
# Check if SCZ_mat adjusts type of output matrix based on
# type of input.
assert isinstance(SCZ, np.ndarray)
assert isinstance(SCZ_sparse, sp.coo_matrix)
assert issparse(SCZ_sparse)
# Check that structure of SCZ matrix is correct.
for mat in (SCZ, SCZ_sparse.toarray()):
assert np.array_equal(mat[:N, :N], np.identity(N))
Expand Down
3 changes: 2 additions & 1 deletion tests/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# pylint: disable=import-outside-toplevel,unused-import

import pytest
import numpy as np
from flamingpy.codes import alternating_polarity


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

result = decode_surface_code(distance, boundaries, ec, noise, decoder, draw=True)
assert result.__class__.__name__ == "bool_"
assert isinstance(result, np.bool_)


def test_gkp_example():
Expand Down
Loading