Skip to content

Commit

Permalink
feat: add source mapping for calibration expansion (#370)
Browse files Browse the repository at this point in the history
* feat: add source mapping for calibration expansion

* refactor instruction calibration expansion so that source maps are only built when returned to the user

* add query (lookup) operations for SourceMap

* make InstructionIndex a newtype struct for source mapping
  • Loading branch information
kalzoo authored Oct 12, 2024
1 parent 9a64a8c commit 9256b95
Show file tree
Hide file tree
Showing 21 changed files with 1,910 additions and 205 deletions.
29 changes: 26 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion quil-py/README-py.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The `quil` package provides tools for constructing, manipulating, parsing, and printing [Quil](https://github.com/quil-lang/quil) programs. Internally, it is powered by [quil-rs](https://github.com/rigetti/quil-rs).

This package is still in early development and breaking changes should be expected between minor versions.
This package is still in development and breaking changes should be expected between minor versions.

# Documentation

Expand Down
96 changes: 90 additions & 6 deletions quil-py/quil/instructions/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,8 @@ class UnaryLogic:
class Calibration:
def __new__(
cls,
name: str,
parameters: Sequence[Expression],
qubits: Sequence[Qubit],
identifier: CalibrationIdentifier,
instructions: Sequence[Instruction],
modifiers: Sequence[GateModifier],
) -> Self: ...
@property
def name(self) -> str: ...
Expand All @@ -856,6 +853,10 @@ class Calibration:
@qubits.setter
def qubits(self, qubits: Sequence[Qubit]) -> None: ...
@property
def identifier(self) -> CalibrationIdentifier: ...
@identifier.setter
def identifier(self, identifier: CalibrationIdentifier) -> None: ...
@property
def instructions(self) -> List[Instruction]: ...
@instructions.setter
def instructions(self, instructions: Sequence[Instruction]) -> None: ...
Expand Down Expand Up @@ -884,11 +885,55 @@ class Calibration:
def __copy__(self) -> Self:
"""Returns a shallow copy of the class."""

class CalibrationIdentifier:
def __new__(
cls,
name: str,
parameters: Sequence[Expression],
qubits: Sequence[Qubit],
modifiers: Sequence[GateModifier],
) -> Self: ...
@property
def name(self) -> str: ...
@name.setter
def name(self, name: str) -> None: ...
@property
def parameters(self) -> List[Expression]: ...
@parameters.setter
def parameters(self, parameters: Sequence[Expression]) -> None: ...
@property
def qubits(self) -> List[Qubit]: ...
@qubits.setter
def qubits(self, qubits: Sequence[Qubit]) -> None: ...
@property
def modifiers(self) -> List[GateModifier]: ...
@modifiers.setter
def modifiers(self, modifiers: Sequence[GateModifier]) -> None: ...
def to_quil(self) -> str:
"""Attempt to convert the instruction to a valid Quil string.
Raises an exception if the instruction can't be converted to valid Quil.
"""
...
def to_quil_or_debug(self) -> str:
"""Convert the instruction to a Quil string.
If any part of the instruction can't be converted to valid Quil, it will be printed in a human-readable debug format.
"""
def __deepcopy__(self, _: Dict) -> Self:
"""Creates and returns a deep copy of the class.
If the instruction contains any ``QubitPlaceholder`` or ``TargetPlaceholder``, then they will be replaced with
new placeholders so resolving them in the copy will not resolve them in the original.
Should be used by passing an instance of the class to ``copy.deepcopy``
"""
def __copy__(self) -> Self:
"""Returns a shallow copy of the class."""

class MeasureCalibrationDefinition:
def __new__(
cls,
qubit: Optional[Qubit],
parameter: str,
identifier: MeasureCalibrationIdentifier,
instructions: Sequence[Instruction],
) -> Self: ...
@property
Expand All @@ -900,6 +945,10 @@ class MeasureCalibrationDefinition:
@parameter.setter
def parameter(self, parameter: str) -> None: ...
@property
def identifier(self) -> MeasureCalibrationIdentifier: ...
@identifier.setter
def identifier(self, identifier: MeasureCalibrationIdentifier) -> None: ...
@property
def instructions(self) -> List[Instruction]: ...
@instructions.setter
def instructions(self, instructions: Sequence[Instruction]) -> None: ...
Expand All @@ -924,6 +973,41 @@ class MeasureCalibrationDefinition:
def __copy__(self) -> Self:
"""Returns a shallow copy of the class."""

class MeasureCalibrationIdentifier:
def __new__(
cls,
qubit: Optional[Qubit],
parameter: str,
) -> Self: ...
@property
def qubit(self) -> Optional[Qubit]: ...
@qubit.setter
def qubit(self, qubit: Optional[Qubit]) -> None: ...
@property
def parameter(self) -> str: ...
@parameter.setter
def parameter(self, parameter: str) -> None: ...
def to_quil(self) -> str:
"""Attempt to convert the instruction to a valid Quil string.
Raises an exception if the instruction can't be converted to valid Quil.
"""
...
def to_quil_or_debug(self) -> str:
"""Convert the instruction to a Quil string.
If any part of the instruction can't be converted to valid Quil, it will be printed in a human-readable debug format.
"""
def __deepcopy__(self, _: Dict) -> Self:
"""Creates and returns a deep copy of the class.
If the instruction contains any ``QubitPlaceholder`` or ``TargetPlaceholder``, then they will be replaced with
new placeholders so resolving them in the copy will not resolve them in the original.
Should be used by passing an instance of the class to ``copy.deepcopy``
"""
def __copy__(self) -> Self:
"""Returns a shallow copy of the class."""

class CircuitDefinition:
def __new__(
cls,
Expand Down
Loading

0 comments on commit 9256b95

Please sign in to comment.