From 85615c55cde83a47434f2101c0d69492bb1846e7 Mon Sep 17 00:00:00 2001 From: Antoine Cornillot <61453516+a-corni@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:34:53 +0100 Subject: [PATCH] Upgrade black version to 24.3.0 to fix vulnerability (#662) * Upgrade black version * upgrade version to v0.17.4 * Run black 24.3.0 * Fix import version --- dev_requirements.txt | 2 +- pulser-core/pulser/devices/_device_datacls.py | 23 +++++++++++-------- pulser-core/pulser/register/_coordinates.py | 1 + pulser-core/pulser/register/_patterns.py | 8 ++++--- pulser-core/pulser/sampler/sampler.py | 1 + pulser-core/pulser/sampler/samples.py | 1 + pulser-core/pulser/sequence/_seq_drawer.py | 18 +++++++++------ pulser-core/pulser/sequence/_seq_str.py | 10 ++++---- pulser-core/pulser/sequence/sequence.py | 8 ++++--- tests/test_simulation.py | 4 +--- 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 37188585f..4057dc9d6 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,5 +1,5 @@ # tests -black[jupyter] ~= 23.1 +black[jupyter] ~= 24.3 flake8 flake8-docstrings isort diff --git a/pulser-core/pulser/devices/_device_datacls.py b/pulser-core/pulser/devices/_device_datacls.py index f7c81a8aa..8e9df06ad 100644 --- a/pulser-core/pulser/devices/_device_datacls.py +++ b/pulser-core/pulser/devices/_device_datacls.py @@ -75,6 +75,7 @@ class BaseDevice(ABC): max_runs: The maximum number of runs allowed on the device. Only used for backend execution. """ + name: str dimensions: DIMENSIONS rydberg_level: int @@ -508,6 +509,7 @@ class Device(BaseDevice): pre_calibrated_layouts: RegisterLayout instances that are already available on the Device. """ + max_atom_num: int max_radial_distance: int pre_calibrated_layouts: tuple[RegisterLayout, ...] = field( @@ -630,15 +632,17 @@ def _specs(self, for_docs: bool = False) -> str: + f" {ch.max_amp:.4g} rad/µs" ), ( - "\t" - + r"- Maximum :math:`|\delta|`:" - + f" {ch.max_abs_detuning:.4g} rad/µs" - ) - if not isinstance(ch, DMM) - else ( - "\t" - + r"- Bottom :math:`|\delta|`:" - + f" {ch.bottom_detuning:.4g} rad/µs" + ( + "\t" + + r"- Maximum :math:`|\delta|`:" + + f" {ch.max_abs_detuning:.4g} rad/µs" + ) + if not isinstance(ch, DMM) + else ( + "\t" + + r"- Bottom :math:`|\delta|`:" + + f" {ch.bottom_detuning:.4g} rad/µs" + ) ), f"\t- Minimum average amplitude: {ch.min_avg_amp} rad/µs", ] @@ -703,6 +707,7 @@ class VirtualDevice(BaseDevice): reusable_channels: Whether each channel can be declared multiple times on the same pulse sequence. """ + min_atom_distance: float = 0 max_atom_num: int | None = None max_radial_distance: int | None = None diff --git a/pulser-core/pulser/register/_coordinates.py b/pulser-core/pulser/register/_coordinates.py index ac104396e..575e65cdd 100644 --- a/pulser-core/pulser/register/_coordinates.py +++ b/pulser-core/pulser/register/_coordinates.py @@ -1,4 +1,5 @@ """Defines a collection of coordinates.""" + from __future__ import annotations import hashlib diff --git a/pulser-core/pulser/register/_patterns.py b/pulser-core/pulser/register/_patterns.py index 6b622e783..ccffe98a1 100644 --- a/pulser-core/pulser/register/_patterns.py +++ b/pulser-core/pulser/register/_patterns.py @@ -118,9 +118,11 @@ def triangular_hex(n_points: int) -> np.ndarray: for side in range(6) for atom in range( 1, - min_atoms_per_side + 2 - if points_left > sides_order[side] - else min_atoms_per_side + 1, + ( + min_atoms_per_side + 2 + if points_left > sides_order[side] + else min_atoms_per_side + 1 + ), ) ], dtype=float, diff --git a/pulser-core/pulser/sampler/sampler.py b/pulser-core/pulser/sampler/sampler.py index 6c5c6b2ea..c46ded256 100644 --- a/pulser-core/pulser/sampler/sampler.py +++ b/pulser-core/pulser/sampler/sampler.py @@ -1,4 +1,5 @@ """The main function for sequence sampling.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Optional diff --git a/pulser-core/pulser/sampler/samples.py b/pulser-core/pulser/sampler/samples.py index 00517f4f2..e88e3c676 100644 --- a/pulser-core/pulser/sampler/samples.py +++ b/pulser-core/pulser/sampler/samples.py @@ -1,4 +1,5 @@ """Dataclasses for storing and processing the samples.""" + from __future__ import annotations import itertools diff --git a/pulser-core/pulser/sequence/_seq_drawer.py b/pulser-core/pulser/sequence/_seq_drawer.py index c123ce8e5..b7d72fb52 100644 --- a/pulser-core/pulser/sequence/_seq_drawer.py +++ b/pulser-core/pulser/sequence/_seq_drawer.py @@ -325,9 +325,11 @@ def gather_qubit_data( if sub_target != set(): pad_times = ( 0 if times == "initial" else target[0], - 0 - if times == "initial" - else total_duration - target[1], + ( + 0 + if times == "initial" + else total_duration - target[1] + ), ) qubit_data[i][tuple(sub_target)] = ( w @@ -935,11 +937,13 @@ def _draw_qubit_content( draw_data = {"input": draw_input, "modulated": draw_modulation} n_data = sum(list(draw_data.values())) qubit_data = [ - gather_qubit_data( - sampled_seq, data, register, (data_name == "modulated") + ( + gather_qubit_data( + sampled_seq, data, register, (data_name == "modulated") + ) + if to_draw + else None ) - if to_draw - else None for data_name, to_draw in draw_data.items() ] # Figure composed of 2 subplots (input, modulated) each composed diff --git a/pulser-core/pulser/sequence/_seq_str.py b/pulser-core/pulser/sequence/_seq_str.py index 8cbd95391..af578a421 100644 --- a/pulser-core/pulser/sequence/_seq_str.py +++ b/pulser-core/pulser/sequence/_seq_str.py @@ -63,10 +63,12 @@ def seq_to_str(sequence: Sequence) -> str: full += dmm_det_line.format( ts.ti, ts.tf, - ts.type.detuning - if not seq.is_detuned_delay(ts.type) - else "{:.3g} rad/µs".format( - cast(float, ts.type.detuning[0]) + ( + ts.type.detuning + if not seq.is_detuned_delay(ts.type) + else "{:.3g} rad/µs".format( + cast(float, ts.type.detuning[0]) + ) ), tgt_txt, ) diff --git a/pulser-core/pulser/sequence/sequence.py b/pulser-core/pulser/sequence/sequence.py index 1bed95b34..c2a3a7697 100644 --- a/pulser-core/pulser/sequence/sequence.py +++ b/pulser-core/pulser/sequence/sequence.py @@ -318,9 +318,11 @@ def available_channels(self) -> dict[str, Channel]: return all_channels else: occupied_ch_ids = [ - self._schedule[ch_name].channel_id - if ch_name in self._schedule - else _dmm_id_from_name(ch_name) + ( + self._schedule[ch_name].channel_id + if ch_name in self._schedule + else _dmm_id_from_name(ch_name) + ) for ch_name in self.declared_channels.keys() ] return { diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 36f31c272..aac1e8c31 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -490,9 +490,7 @@ def test_run(seq, patch_plt_show): good_initial_qobj = qutip.tensor( [qutip.basis(sim.dim, 0) for _ in range(sim._hamiltonian._size)] ) - good_initial_qobj_no_dims = qutip.basis( - sim.dim**sim._hamiltonian._size, 2 - ) + good_initial_qobj_no_dims = qutip.basis(sim.dim**sim._hamiltonian._size, 2) with pytest.raises( ValueError, match="Incompatible shape of initial state"