Skip to content

Commit

Permalink
Type annotations for gates, quilatom, and quilbase modules (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleby authored and karalekas committed Oct 31, 2019
1 parent e59fea5 commit 4011664
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 302 deletions.
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

0 comments on commit 4011664

Please sign in to comment.