Skip to content

Commit

Permalink
Fix Numpy 1.25 compatibility (#537)
Browse files Browse the repository at this point in the history
* Fix failing CI tests

* Fix deprecation warnings

* Fix mypy errors

* Bring coverage back up

* Bump to version 0.13.1
  • Loading branch information
HGSilveri authored Jun 20, 2023
1 parent 34f9ea8 commit 82e2547
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ files =
pulser-simulation/pulser_simulation,
pulser-pasqal/pulser_pasqal,
tests
python_version = 3.8
python_version = 3.11
warn_return_any = True
warn_redundant_casts = True
warn_unused_ignores = True
disallow_untyped_defs = True

# 3rd-party libs without type hints nor stubs
[mypy-matplotlib.*,scipy.*,qutip.*,jsonschema.*]
[mypy-matplotlib.*,scipy.*,qutip.*,jsonschema.*,py.*]
follow_imports = silent
ignore_missing_imports = True

Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.0
0.13.1
3 changes: 2 additions & 1 deletion pulser-core/pulser/json/supported.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

SUPPORTED_NUMPY = (
"array",
"round_",
"round", # numpy >= 1.25
"round_", # numpy < 1.25
"ceil",
"floor",
"sqrt",
Expand Down
2 changes: 1 addition & 1 deletion pulser-simulation/pulser_simulation/qutip_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_state(
is_density_matrix = state.isoper
if ignore_global_phase and not is_density_matrix:
full = state.full()
global_ph = float(np.angle(full[np.argmax(np.abs(full))]))
global_ph = float(np.angle(full[np.argmax(np.abs(full))])[0])
state *= np.exp(-1j * global_ph)
if self._dim != 3:
if reduce_to_basis not in [None, self._basis_name]:
Expand Down
12 changes: 11 additions & 1 deletion tests/test_abstract_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,17 @@ def test_deserialize_param(self, json_param):
"var1": {"type": "float", "value": [1.5]},
},
)
_check_roundtrip(s)
# Note: If built, some of these sequences will be invalid
# since they are giving an array of size 1 to a parameter
# where a single value is expected. Still, all we want to
# see is whether the parametrization of the operations
# works as expected
if (
json_param["lhs"] != {"variable": "var1"}
and json_param["expression"] != "index"
):
_check_roundtrip(s)

seq = Sequence.from_abstract_repr(json.dumps(s))
seq_var1 = seq._variables["var1"]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_parametrized.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def t():

@pytest.fixture
def bwf(t, a):
return BlackmanWaveform(t, a)
return BlackmanWaveform(t[0], a[0])


def test_var(a, b):
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_paramobj(bwf, t, a, b):
assert set(bwf.variables.keys()) == {"t", "a"}
pulse = Pulse.ConstantDetuning(bwf, b[0], b[1])
assert set(pulse.variables.keys()) == {"t", "a", "b"}
assert str(bwf) == "BlackmanWaveform(t, a)"
assert str(bwf) == "BlackmanWaveform(t[0], a[0])"
assert str(pulse) == f"Pulse.ConstantDetuning({str(bwf)}, b[0], b[1])"
pulse2 = Pulse(bwf, bwf, 1)
assert str(pulse2) == f"Pulse({str(bwf)}, {str(bwf)}, 1)"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_blackman():
wf = BlackmanWaveform(100, -2)
assert np.isclose(wf.integral, -2)
assert np.all(wf.samples <= 0)
assert wf == BlackmanWaveform(100, np.array([-2]))
assert wf == BlackmanWaveform(100, np.array(-2))

with pytest.raises(ValueError, match="matching signs"):
BlackmanWaveform.from_max_val(-10, np.pi)
Expand All @@ -185,7 +185,7 @@ def test_blackman():
assert np.min(wf.samples) > -10

var = Variable("var", float)
wf_var = BlackmanWaveform.from_max_val(-10, var)
wf_var = BlackmanWaveform.from_max_val(-10, var[0])
assert isinstance(wf_var, ParamObj)
var._assign(-np.pi)
assert wf_var.build() == wf
Expand Down

0 comments on commit 82e2547

Please sign in to comment.