Skip to content

Commit

Permalink
Add pylint fix (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nans authored Jul 29, 2024
1 parent f69bc8a commit 95912f1
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion perceval/algorithm/tomography/tomography_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from itertools import product, combinations
from perceval.components import (PauliType, PauliEigenStateType, get_pauli_gate, get_pauli_eigen_state_prep_circ,
processor_circuit_configurator)
from perceval.algorithm import Sampler
from ..sampler import Sampler
from perceval.utils import BasicState


Expand Down
2 changes: 1 addition & 1 deletion perceval/components/linear_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from perceval.components.abstract_component import AParametrizedComponent
from perceval.utils import Parameter, Matrix, MatrixN, matrix_double, global_params, InterferometerShape
import perceval.utils.algorithms.decomposition as decomposition
from perceval.utils.algorithms import decomposition
from perceval.utils.algorithms.match import Match
from perceval.utils.algorithms.solve import solve

Expand Down
4 changes: 2 additions & 2 deletions perceval/components/tomography_exp_configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def processor_circuit_configurator(processor, prep_state_indices: list, meas_pau

if not all(isinstance(p_index, PauliEigenStateType) for p_index in prep_state_indices):
raise TypeError(
f"Indices for the preparation circuits should be a PauliEigenStateType")
"Indices for the preparation circuits should be a PauliEigenStateType")

if not all(isinstance(m_index, PauliType) for m_index in meas_pauli_basis_indices):
raise TypeError(
f"Indices for the measurement circuits should be a PauliType")
"Indices for the measurement circuits should be a PauliType")

p = processor.copy()
p.clear_input_and_circuit(processor.m) # Clear processor content but keep its size
Expand Down
2 changes: 1 addition & 1 deletion perceval/rendering/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, inverse_Y=False, **opts):
self._opts = {}
else:
self._opts = opts
self._inverse_Y = inverse_Y and -1 or 1
self._inverse_Y = -1 if inverse_Y else 1
self._background_color = None

def set_offset(self, v: Tuple[float, float], width: float, height: float):
Expand Down
4 changes: 2 additions & 2 deletions perceval/rendering/circuit/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ def create_renderer(
n: int, # number of modes
output_format: Format = Format.TEXT, # rendering method
skin: ASkin = None, # skin (unused in text rendering)
**opts
) -> ICircuitRenderer:
**opts,
) -> tuple[ICircuitRenderer, ICircuitRenderer]:
"""
Creates a renderer given the selected format. Dispatches parameters to generated canvas objects
A skin object is needed for circuit graphic rendering.
Expand Down
9 changes: 3 additions & 6 deletions perceval/rendering/pdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
from .format import Format
from ._processor_utils import collect_herald_info

import math


in_notebook = False

Expand Down Expand Up @@ -174,14 +172,13 @@ def pdisplay_matrix(matrix: Matrix, precision: float = 1e-6, output_format: Form
"""

def simp(value):
if isinstance(value, complex) or isinstance(value, int) or isinstance(value, float) or\
isinstance(value, sp.Number) or (isinstance(value, sp.Expr) and len(value.free_symbols) == 0):
if isinstance(value, (complex, float, int, sp.Number)) or (isinstance(value, sp.Expr) and len(value.free_symbols) == 0):
return simple_complex(complex(value), precision=precision)[1]
else:
return value.__repr__()

if output_format != Format.TEXT:
marker = output_format == Format.HTML and "$" or ""
marker = output_format == "$" if Format.HTML else ""
if isinstance(matrix, sp.Matrix):
return marker + sp.latex(matrix) + marker
rows = []
Expand Down Expand Up @@ -543,7 +540,7 @@ def pdisplay_to_file(o, path: str, output_format: Format = None, **opts):
else:
res.save_svg(path)
return
except:
except Exception:
pass

if output_format == Format.LATEX:
Expand Down
2 changes: 1 addition & 1 deletion perceval/runtime/remote_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _extract_job_times(response):
creation_datetime = float(response['creation_datetime'])
start_time = float(response['start_time'])
duration = int(response['duration'])
except:
except Exception:
pass
return creation_datetime, duration, start_time

Expand Down
16 changes: 15 additions & 1 deletion perceval/serialization/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@
from perceval.components import Circuit
from perceval.utils import Matrix, BSDistribution, SVDistribution, BasicState, BSCount, NoiseModel, PostSelect
from perceval.serialization import _matrix_serialization, deserialize_state
from ._constants import *
from ._constants import (
SEP,
PCVL_PREFIX,
ZIP_PREFIX,
BS_TAG,
SV_TAG,
SVD_TAG,
BSD_TAG,
BSC_TAG,
BSS_TAG,
MATRIX_TAG,
CIRCUIT_TAG,
NOISE_TAG,
POSTSELECT_TAG,
)
from ._state_serialization import deserialize_statevector, deserialize_bssamples
from . import _component_deserialization as _cd
from . import _schema_circuit_pb2 as pb
Expand Down
1 change: 1 addition & 0 deletions perceval/utils/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def simp(self):
"""Simplify the matrix - only implemented for symbolic matrix"""
return self

@staticmethod
def _read(seqline: Iterator[str]) -> Matrix:
"""read a matrix from file or a string sequence"""
rows = []
Expand Down
2 changes: 1 addition & 1 deletion perceval/utils/persistent_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def delete_file(self, filename: str):
try:
os.remove(file_path)
except OSError:
warnings.warn(UserWarning(f"Cannot delete persistent file {file_path}"))
warnings.warn(UserWarning("Cannot delete persistent file {file_path}"))

def write_file(self, filename: str, data: Union[bytes, str], file_format: FileFormat):
"""Write data into a file in persistent data directory
Expand Down

0 comments on commit 95912f1

Please sign in to comment.