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

feat: Update quil to >=0.13.2 #1809

Merged
merged 5 commits into from
Dec 11, 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
83 changes: 42 additions & 41 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ scipy = "^1.11"
rpcq = "^3.11.0"
networkx = ">=2.5"
qcs-sdk-python = ">=0.20.1"
quil = ">=0.11.2"
quil = ">=0.13.2"
packaging = "^23.1"
deprecated = "^1.2.14"
types-deprecated = "^1.2.9.3"
Expand Down 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
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
59 changes: 36 additions & 23 deletions pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2772,41 +2772,40 @@ def __new__(
"""Initialize a new calibration definition."""
return super().__new__(
cls,
name,
_convert_to_rs_expressions(parameters),
_convert_to_rs_qubits(qubits),
quil_rs.CalibrationIdentifier(
name,
_convert_to_rs_expressions(parameters),
_convert_to_rs_qubits(qubits),
modifiers or [],
),
_convert_to_rs_instructions(instrs),
modifiers or [],
)

@classmethod
def _from_rs_calibration(cls, calibration: quil_rs.Calibration) -> "DefCalibration":
return super().__new__(
cls,
calibration.name,
calibration.parameters,
calibration.qubits,
calibration.instructions,
calibration.modifiers,
)
return super().__new__(cls, calibration.identifier, calibration.instructions)

@property # type: ignore[override]
def parameters(self) -> Sequence[ParameterDesignator]:
"""The parameters of the calibration."""
return _convert_to_py_expressions(super().parameters)
return _convert_to_py_expressions(super().identifier.parameters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I can't get the type stubs to agree, looks like rigetti/quil-rs#420 is resolved because the types are correct in https://github.com/rigetti/quil-rs/blob/main/quil-py/quil/instructions/__init__.pyi#L888-L897 but not when I install quil-rs==0.13.2... but, this should be the same thing and gets the test passing.


@parameters.setter
def parameters(self, parameters: Sequence[ParameterDesignator]) -> None:
quil_rs.Calibration.parameters.__set__(self, _convert_to_rs_expressions(parameters)) # type: ignore[attr-defined] # noqa
identifier = super().identifier
identifier.parameters = _convert_to_rs_expressions(parameters)
quil_rs.Calibration.identifier.__set__(self, identifier) # type: ignore[attr-defined] # noqa

@property # type: ignore[override]
def qubits(self) -> list[QubitDesignator]:
"""The qubits the calibration operates on."""
return _convert_to_py_qubits(super().qubits)
return _convert_to_py_qubits(super().identifier.qubits)

@qubits.setter
def qubits(self, qubits: Sequence[QubitDesignator]) -> None:
quil_rs.Calibration.qubits.__set__(self, _convert_to_rs_qubits(qubits)) # type: ignore[attr-defined]
identifier = super().identifier
identifier.qubits = _convert_to_rs_qubits(qubits)
quil_rs.Calibration.identifier.__set__(self, identifier) # type: ignore[attr-defined]

@property
def instrs(self) -> list[AbstractInstruction]:
Expand All @@ -2826,6 +2825,17 @@ def instructions(self) -> list[AbstractInstruction]:
def instructions(self, instructions: list[AbstractInstruction]) -> None:
self.instrs = instructions

@property
def name(self) -> str:
"""Get the name of the calibration."""
return super().identifier.name

@name.setter
def name(self, name: str) -> None:
identifier = super().identifier
identifier.name = name
quil_rs.Calibration.identifier.__set__(self, identifier) # type: ignore

def out(self) -> str:
"""Return the instruction as a valid Quil string."""
return super().to_quil()
Expand Down Expand Up @@ -2854,37 +2864,40 @@ def __new__(
rs_qubit = None if not qubit else _convert_to_rs_qubit(qubit)
return super().__new__(
cls,
rs_qubit,
memory_reference.name,
quil_rs.MeasureCalibrationIdentifier(rs_qubit, str(memory_reference)),
_convert_to_rs_instructions(instrs),
)

@classmethod
def _from_rs_measure_calibration_definition(
cls, calibration: quil_rs.MeasureCalibrationDefinition
) -> "DefMeasureCalibration":
return super().__new__(cls, calibration.qubit, calibration.parameter, calibration.instructions)
return super().__new__(cls, calibration.identifier, calibration.instructions)

@property # type: ignore[override]
def qubit(self) -> Optional[QubitDesignator]:
"""Get the qubit this calibration matches."""
qubit = super().qubit
qubit = super().identifier.qubit
if not qubit:
return None
return _convert_to_py_qubit(qubit)

@qubit.setter
def qubit(self, qubit: QubitDesignator) -> None:
quil_rs.MeasureCalibrationDefinition.qubit.__set__(self, _convert_to_rs_qubit(qubit)) # type: ignore[attr-defined] # noqa
identifier = super().identifier
identifier.qubit = _convert_to_rs_qubit(qubit)
quil_rs.MeasureCalibrationDefinition.identifier.__set__(self, identifier) # type: ignore[attr-defined] # noqa

@property
def memory_reference(self) -> Optional[MemoryReference]:
"""Get the memory reference this calibration writes to."""
return MemoryReference._from_parameter_str(super().parameter)
return MemoryReference._from_parameter_str(super().identifier.parameter)

@memory_reference.setter
def memory_reference(self, memory_reference: MemoryReference) -> None:
quil_rs.MeasureCalibrationDefinition.parameter.__set__(self, memory_reference.name) # type: ignore[attr-defined] # noqa
identifier = super().identifier
identifier.parameter = memory_reference.out()
quil_rs.MeasureCalibrationDefinition.identifier.__set__(self, identifier) # type: ignore[attr-defined] # noqa

@property
def instrs(self) -> list[AbstractInstruction]:
Expand Down
Loading
Loading