Skip to content

Commit

Permalink
update bench fixture, re-enable pyquil DefCalibration
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Mar 25, 2024
1 parent 77d1157 commit 3e95298
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 71 deletions.
131 changes: 64 additions & 67 deletions src/pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
import quil.expression as quil_rs_expr
import quil.instructions as quil_rs

from pyquil._instruction import DefCalibration


class _InstructionMeta(abc.ABCMeta):
"""A metaclass that allows us to group all instruction types from quil-rs and pyQuil as an `AbstractInstruction`.
Expand Down Expand Up @@ -2504,71 +2502,70 @@ def __deepcopy__(self, memo: Dict) -> "DefCircuit":
return DefCircuit._from_rs_circuit_definition(super().__deepcopy__(memo))


# class DefCalibration(quil_rs.Calibration, AbstractInstruction):
# def __new__(
# cls,
# name: str,
# parameters: Sequence[ParameterDesignator],
# qubits: Sequence[Union[Qubit, FormalArgument]],
# instrs: Sequence[AbstractInstruction],
# modifiers: Optional[List[quil_rs.GateModifier]] = None,
# ) -> Self:
# return super().__new__(
# cls,
# name,
# _convert_to_rs_expressions(parameters),
# _convert_to_rs_qubits(qubits),
# _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,
# )
#
# @property # type: ignore[override]
# def parameters(self) -> Sequence[ParameterDesignator]:
# return _convert_to_py_expressions(super().parameters)
#
# @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
#
# @property # type: ignore[override]
# def qubits(self) -> List[QubitDesignator]:
# return _convert_to_py_qubits(super().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]
#
# @property
# def instrs(self) -> List[AbstractInstruction]:
# return _convert_to_py_instructions(super().instructions)
#
# @instrs.setter
# def instrs(self, instrs: Sequence[AbstractInstruction]) -> None:
# quil_rs.Calibration.instructions.__set__(self, _convert_to_rs_instructions(instrs)) # type: ignore[attr-defined] # noqa
#
# def out(self) -> str:
# return super().to_quil()
#
# def __str__(self) -> str:
# return super().to_quil_or_debug()
#
# def __copy__(self) -> Self:
# return self
#
# def __deepcopy__(self, memo: Dict) -> "DefCalibration":
# return DefCalibration._from_rs_calibration(super().__deepcopy__(memo))
#
class DefCalibration(quil_rs.Calibration, AbstractInstruction):
def __new__(
cls,
name: str,
parameters: Sequence[ParameterDesignator],
qubits: Sequence[Union[Qubit, FormalArgument]],
instrs: Sequence[AbstractInstruction],
modifiers: Optional[List[quil_rs.GateModifier]] = None,
) -> Self:
return super().__new__(
cls,
name,
_convert_to_rs_expressions(parameters),
_convert_to_rs_qubits(qubits),
_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,
)

@property # type: ignore[override]
def parameters(self) -> Sequence[ParameterDesignator]:
return _convert_to_py_expressions(super().parameters)

@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

@property # type: ignore[override]
def qubits(self) -> List[QubitDesignator]:
return _convert_to_py_qubits(super().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]

@property
def instrs(self) -> List[AbstractInstruction]:
return _convert_to_py_instructions(super().instructions)

@instrs.setter
def instrs(self, instrs: Sequence[AbstractInstruction]) -> None:
quil_rs.Calibration.instructions.__set__(self, _convert_to_rs_instructions(instrs)) # type: ignore[attr-defined] # noqa

def out(self) -> str:
return super().to_quil()

def __str__(self) -> str:
return super().to_quil_or_debug()

def __copy__(self) -> Self:
return self

def __deepcopy__(self, memo: Dict) -> "DefCalibration":
return DefCalibration._from_rs_calibration(super().__deepcopy__(memo))


class DefMeasureCalibration(quil_rs.MeasureCalibrationDefinition, AbstractInstruction):
Expand Down
8 changes: 4 additions & 4 deletions test/bench/fixtures/over-9000.quil
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,6 @@ RZ(1.6723803444036598) 4
CNOT 5 8
RZ(4.81533948533556) 1
CNOT 0 8

CNOT 1 3
RZ(4.091531092109592) 0
CNOT 0 2
Expand Down Expand Up @@ -3321,7 +3320,6 @@ RZ(1.6723803444036598) 4
CNOT 5 8
RZ(4.81533948533556) 1
CNOT 0 8

CNOT 1 3
RZ(4.091531092109592) 0
CNOT 0 2
Expand Down Expand Up @@ -5221,7 +5219,6 @@ RZ(1.6723803444036598) 4
CNOT 5 8
RZ(4.81533948533556) 1
CNOT 0 8

CNOT 1 3
RZ(4.091531092109592) 0
CNOT 0 2
Expand Down Expand Up @@ -7120,7 +7117,6 @@ RZ(1.6723803444036598) 4
CNOT 5 8
RZ(4.81533948533556) 1
CNOT 0 8

CNOT 1 3
RZ(4.091531092109592) 0
CNOT 0 2
Expand Down Expand Up @@ -8999,3 +8995,7 @@ RX(4.341787227340024) 1
RY(6.03481174851813) 3
CNOT 2 7
CNOT 1 3
CNOT 1 3
CNOT 1 3
CNOT 1 3
RY(6.03481174851813) 3

0 comments on commit 3e95298

Please sign in to comment.