Skip to content

Commit

Permalink
fix various lints, and remove deprecated numpy constants
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Nov 13, 2024
1 parent 7026c25 commit 4215978
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ indent-width = 4
target-version = "py39"

[tool.ruff.lint]
select = ["D", "E4", "E7", "E9", "F", "I", "B", "S", "UP", "W"]
select = ["D", "E4", "E7", "E9", "F", "I", "B", "S", "UP", "W", "NPY201"]
ignore = [
"D105", # Allow missing documentation in dunder method.
"D203", # This conflicts with D211.
Expand Down
2 changes: 1 addition & 1 deletion pyquil/latex/_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ def display(circuit: Program, settings: Optional[DiagramSettings] = None, **imag
msg += " Transcript:\n\n" + result.stderr.decode("utf-8")
raise RuntimeError(msg)

return Image(filename=png, **image_options)
return Image(filename=png, **image_options) # type: ignore
4 changes: 2 additions & 2 deletions pyquil/paulis.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def combined_exp_wrap(param: float) -> Program:

def exponentiate_pauli_sum(
pauli_sum: Union[PauliSum, PauliTerm],
) -> NDArray[np.complex_]:
) -> NDArray[np.complex128]:
r"""Exponentiate a sequence of PauliTerms, which may or may not commute.
The Pauliterms must have fixed (non-parametric) coefficients. The coefficients are interpreted in cycles rather than
Expand Down Expand Up @@ -995,7 +995,7 @@ def exponentiate_pauli_sum(
matrices.append(matrix)
generated_unitary = expm(-1j * np.pi * sum(matrices))
phase = np.exp(-1j * np.angle(generated_unitary[0, 0]))
return np.asarray(phase * generated_unitary, dtype=np.complex_)
return np.asarray(phase * generated_unitary, dtype=np.complex128)


def _exponentiate_general_case(pauli_term: PauliTerm, param: float) -> Program:
Expand Down
4 changes: 2 additions & 2 deletions pyquil/pyqvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

log = logging.getLogger(__name__)

QUIL_TO_NUMPY_DTYPE = {"INT": np.int_, "REAL": np.float_, "BIT": np.int8, "OCTET": np.uint8}
QUIL_TO_NUMPY_DTYPE = {"INT": np.int32, "REAL": np.float64, "BIT": np.int8, "OCTET": np.uint8}


class AbstractQuantumSimulator(ABC):
Expand Down Expand Up @@ -387,7 +387,7 @@ def transition(self) -> bool:
target = instruction.target
old = self.ram[target.name][target.offset]
if isinstance(instruction, ClassicalNeg):
if not isinstance(old, (int, float, np.int_, np.float_)):
if not isinstance(old, (int, float, np.int32, np.float64)):
raise ValueError(f"NEG requires a data type of REAL or INTEGER; not {type(old)}")
self.ram[target.name][target.offset] *= -1
elif isinstance(instruction, ClassicalNot):
Expand Down
3 changes: 2 additions & 1 deletion pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2825,8 +2825,9 @@ def instructions(self) -> list[AbstractInstruction]:
def instructions(self, instructions: list[AbstractInstruction]) -> None:
self.instrs = instructions

@property
@property # type: ignore[override]
def name(self) -> str:
"""Get the name of the calibration."""
return super().identifier.name

@name.setter
Expand Down
3 changes: 2 additions & 1 deletion pyquil/quiltcalibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def _convert_to_calibration_match(
target_values = (
[] if not instruction.target else [MemoryReference._from_rs_memory_reference(instruction.target)]
)
parameter_qubits = [] if not calibration.qubit() else [calibration.qubit()]
calibration_qubit = calibration.qubit()
parameter_qubits = [] + [calibration_qubit] if calibration_qubit else []
parameter_values = [MemoryReference._from_parameter_str(calibration.identifier.parameter)]
py_calibration = DefMeasureCalibration._from_rs_measure_calibration_definition(calibration)
else:
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ def test_readout_compensation():
for ap in aps:
ap.flat[ap.flat < 0] = 0.0
ap /= ap.sum()
assert np.alltrue(ap >= 0)
assert (ap >= 0).all()

assert np.alltrue(p >= 0)
assert (p >= 0).all()

p_corrupted = corrupt_bitstring_probs(p, aps)
p_restored = correct_bitstring_probs(p_corrupted, aps)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_quilatom.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ def test_qubit_placeholder():

def test_arithmetic_with_numpy():
x = Parameter("x")
expression = np.float_(1.0) + x
assert expression == Add(np.float_(1.0), x)
expression = np.float64(1.0) + x
assert expression == Add(np.float64(1.0), x)

0 comments on commit 4215978

Please sign in to comment.