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

Type annotations for gates, quilatom, and quilbase modules #999

Merged
merged 25 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0658e22
Add type annotations to the gates module
appleby Sep 16, 2019
0d7de29
Add type annotations to the quilatom module
appleby Sep 16, 2019
6729038
Fix flake8 issues
appleby Sep 16, 2019
1aa3649
Resolve remaining TODO comments in source
appleby Sep 17, 2019
0570f4e
Update the changelog for gh-999
appleby Sep 17, 2019
abf326e
Appease sphinx by importing quilatom.Expression in gates.py
appleby Sep 17, 2019
6989860
Fix the return type for operator_estimation._stats_from_measurements
appleby Sep 17, 2019
224e590
Silence mypy complaints about from pyquil.gates import *
appleby Sep 17, 2019
25f8088
Fix return type of ForestConnection._qvm_get_version_info
appleby Sep 17, 2019
e60338f
Satisfy mypy --strict about pyquil.quilatom type hints
appleby Sep 17, 2019
b937c70
Update docstrings and error messages to match updated type hints
appleby Sep 23, 2019
7edfc8a
Add type annotations for the quilbase module
appleby Oct 9, 2019
8268edb
Nix return type hints for __init__ methods in quilatom.py
appleby Oct 9, 2019
5db4522
Replace List types with more generic container types where possible
appleby Oct 9, 2019
9cd30ce
Replace Dict types with more generic container types where possible
appleby Oct 9, 2019
2b39dbc
Remove types from docstrings
appleby Oct 9, 2019
204a16d
Appease mypy by adding a QubitPlaceholder.index @property
appleby Oct 10, 2019
8e930b4
Ensure that right operand of OR is a MemoryReference
appleby Oct 10, 2019
3ca6df3
Add type hint for previously untyped quil_cis
appleby Oct 10, 2019
1f08a54
Update CHANGELOG blurb to include quilbase module
appleby Oct 10, 2019
21042ff
Reduce type aliases and standardize on "Designator" suffix
appleby Oct 30, 2019
ea86963
Nix unpack_reg_val_pair overloads and replace with isinstance asserts
appleby Oct 30, 2019
c2a2b98
Rename Executable type alias to ExecutableDesignator
appleby Oct 30, 2019
380bec2
Prefer dangling close paren for overlong function signatures
appleby Oct 30, 2019
4072509
Replace references to DeclareOffsets type alias with Union
appleby Oct 30, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Changelog
the `--runslow` option is specified for `pytest` (@kilimanjaro, gh-1001).
- `PauliSum` objects can now be constructed from strings via `from_compact_str()`
and `PauliTerm.from_compact_str()` supports multi-qubit strings (@jlbosse, gh-984).
- Type hints have been added to the `pyquil.gates`, `pyquil.quilatom`, and `pyquil.quilbase`
modules (@appleby gh-999).

### Bugfixes

Expand Down
6 changes: 5 additions & 1 deletion pyquil/_parser/PyQuilListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ def exitLogicalBinaryOp(self, ctx):
if ctx.AND():
self.result.append(ClassicalAnd(left, right))
elif ctx.OR():
self.result.append(ClassicalOr(left, right))
if isinstance(right, MemoryReference):
self.result.append(ClassicalOr(left, right))
else:
raise RuntimeError("Right operand of deprecated OR instruction must be a"
f" MemoryReference, but found '{right}'")
elif ctx.IOR():
self.result.append(ClassicalInclusiveOr(left, right))
elif ctx.XOR():
Expand Down
2 changes: 1 addition & 1 deletion pyquil/api/_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _qvm_run(self, quil_program, classical_addresses, trials,
return ram

@_record_call
def _qvm_get_version_info(self) -> dict:
def _qvm_get_version_info(self) -> str:
"""
Return version information for the QVM.

Expand Down
6 changes: 3 additions & 3 deletions pyquil/api/_quantum_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from pyquil.quil import Program, validate_supported_quil


Executable = Union[BinaryExecutableResponse, PyQuilExecutableResponse]
ExecutableDesignator = Union[BinaryExecutableResponse, PyQuilExecutableResponse]


class QuantumComputer:
Expand Down Expand Up @@ -107,7 +107,7 @@ def get_isa(self, oneq_type: str = 'Xhalves',
return self.device.get_isa(oneq_type=oneq_type, twoq_type=twoq_type)

@_record_call
def run(self, executable: Executable,
def run(self, executable: ExecutableDesignator,
memory_map: Dict[str, List[Union[int, float]]] = None) -> np.ndarray:
"""
Run a quil executable. If the executable contains declared parameters, then a memory
Expand Down Expand Up @@ -261,7 +261,7 @@ def compile(
protoquil_positional: bool = None,
*,
protoquil: bool = None,
) -> Union[BinaryExecutableResponse, PyQuilExecutableResponse]:
) -> ExecutableDesignator:
"""
A high-level interface to program compilation.

Expand Down
4 changes: 2 additions & 2 deletions pyquil/api/_qvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_version_info(self):
"""
Return version information for the QVM.

:return: Dictionary with version information
:return: String with version information
"""
return self._connection._qvm_get_version_info()

Expand Down Expand Up @@ -448,7 +448,7 @@ def get_version_info(self):
"""
Return version information for the QVM.

:return: Dictionary with version information
:return: String with version information
"""
return self.connection._qvm_get_version_info()

Expand Down
Loading