Skip to content

Commit

Permalink
Merge pull request #35 from CQCL/release/1.21.0
Browse files Browse the repository at this point in the history
Release/1.21.0
  • Loading branch information
cqc-melf authored Oct 17, 2023
2 parents 31bc616 + e65e3e6 commit 7735aec
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
os: ['ubuntu-22.04', 'macos-12', 'windows-2022']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
needs: publish_to_pypi
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set up Python 3.10
Expand All @@ -137,7 +137,7 @@ jobs:
mkdir extensions
./build-docs -d ${GITHUB_WORKSPACE}/.github/workflows/docs/extensions/api
- name: Upload docs as artefact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v2
with:
path: .github/workflows/docs/extensions

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: build docs
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def correct_signature(
signature: str,
return_annotation: str,
) -> (str, str):

new_signature = signature
new_return_annotation = return_annotation
for k, v in app.config.custom_internal_mapping.items():
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion _metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__extension_version__ = "0.29.0"
__extension_version__ = "0.30.0"
__extension_name__ = "pytket-pyquil"
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
~~~~~~~~~

0.30.0 (October 2023)
---------------------

* Updated pytket version requirement to 1.21.

0.29.0 (July 2023)
------------------

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace_packages = True
check_untyped_defs = True

warn_redundant_casts = True
warn_unused_ignores = False
warn_unused_ignores = True
warn_no_return = False
warn_return_any = True
warn_unreachable = True
Expand Down
2 changes: 1 addition & 1 deletion pytket/extensions/pyquil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"""Module for conversion between Rigetti pyQuil and tket primitives."""

# _metadata.py is copied to the folder after installation.
from ._metadata import __extension_version__, __extension_name__ # type: ignore
from ._metadata import __extension_version__, __extension_name__
from .backends import ForestBackend, ForestStateBackend
from .pyquil_convert import pyquil_to_tk, tk_to_pyquil, process_characterisation
32 changes: 16 additions & 16 deletions pytket/extensions/pyquil/backends/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pyquil.paulis import ID, PauliSum, PauliTerm
from pyquil.quilatom import Qubit as Qubit_

from pytket.circuit import Circuit, OpType, Qubit # type: ignore
from pytket.circuit import Circuit, OpType, Qubit, Node
from pytket.backends import (
Backend,
CircuitNotRunError,
Expand All @@ -41,7 +41,7 @@
from pytket.backends.backendresult import BackendResult
from pytket.backends.resulthandle import _ResultIdTuple
from pytket.extensions.pyquil._metadata import __extension_version__
from pytket.passes import ( # type: ignore
from pytket.passes import (
BasePass,
EulerAngleReduction,
CXMappingPass,
Expand All @@ -55,8 +55,8 @@
SimplifyInitial,
NaivePlacementPass,
)
from pytket.pauli import QubitPauliString # type: ignore
from pytket.predicates import ( # type: ignore
from pytket.pauli import QubitPauliString
from pytket.predicates import (
NoSymbolsPredicate,
ConnectivityPredicate,
GateSetPredicate,
Expand All @@ -71,8 +71,8 @@
get_avg_characterisation,
tk_to_pyquil,
)
from pytket.placement import NoiseAwarePlacement # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.placement import NoiseAwarePlacement
from pytket.architecture import Architecture
from pytket.utils import prepare_circuit
from pytket.utils.operators import QubitPauliOperator
from pytket.utils.outcomearray import OutcomeArray
Expand Down Expand Up @@ -128,7 +128,7 @@ def required_predicates(self) -> List[Predicate]:
NoFastFeedforwardPredicate(),
NoMidMeasurePredicate(),
GateSetPredicate(self.backend_info.gate_set),
ConnectivityPredicate(self.backend_info.architecture),
ConnectivityPredicate(self.backend_info.architecture), # type: ignore
]

def rebase_pass(self) -> BasePass:
Expand All @@ -146,17 +146,17 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
passlist.append(FullPeepholeOptimise())
passlist.append(
CXMappingPass(
self.backend_info.architecture,
self.backend_info.architecture, # type: ignore
NoiseAwarePlacement(
self._backend_info.architecture,
self._backend_info.averaged_node_gate_errors,
self._backend_info.averaged_edge_gate_errors,
self._backend_info.architecture, # type: ignore
self._backend_info.averaged_node_gate_errors, # type: ignore
self._backend_info.averaged_edge_gate_errors, # type: ignore
),
directed_cx=False,
delay_measures=True,
)
)
passlist.append(NaivePlacementPass(self.backend_info.architecture))
passlist.append(NaivePlacementPass(self.backend_info.architecture)) # type: ignore
if optimisation_level == 2:
passlist.append(CliffordSimp(False))
if optimisation_level > 0:
Expand Down Expand Up @@ -280,7 +280,7 @@ def _get_backend_info(cls, qc: QuantumComputer) -> BackendInfo:
char_dict: dict = process_characterisation(qc)
arch = char_dict.get("Architecture", Architecture([]))
node_errors = char_dict.get("NodeErrors")
link_errors = char_dict.get("EdgeErrors")
link_errors: dict[tuple[Node, Node], float] = char_dict.get("EdgeErrors") # type: ignore
averaged_errors = get_avg_characterisation(char_dict)
return BackendInfo(
cls.__name__,
Expand All @@ -289,9 +289,9 @@ def _get_backend_info(cls, qc: QuantumComputer) -> BackendInfo:
arch,
cls._GATE_SET,
all_node_gate_errors=node_errors,
all_edge_gate_errors=link_errors,
all_edge_gate_errors=link_errors, # type: ignore
averaged_node_gate_errors=averaged_errors["node_errors"],
averaged_edge_gate_errors=averaged_errors["link_errors"],
averaged_edge_gate_errors=averaged_errors["link_errors"], # type: ignore
)

@classmethod
Expand Down Expand Up @@ -450,7 +450,7 @@ def get_operator_expectation_value(
"""
prog = tk_to_pyquil(state_circuit)
pauli_sum = PauliSum(
[self._gen_PauliTerm(term, coeff) for term, coeff in operator._dict.items()]
[self._gen_PauliTerm(term, coeff) for term, coeff in operator._dict.items()] # type: ignore
)
return complex(self._sim.expectation(prog, pauli_sum))

Expand Down
54 changes: 29 additions & 25 deletions pytket/extensions/pyquil/pyquil_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
Function as Function_,
)
from pyquil.quilbase import Declare, Gate, Halt, Measurement, Pragma
from sympy import pi, Expr, Symbol, sin, cos, Number, Add, Mul, Pow # type: ignore
from sympy import pi, Expr, Symbol, sin, cos, Number, Add, Mul, Pow

from pytket.circuit import Circuit, Node, OpType, Qubit, Bit # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.circuit import Circuit, Node, OpType, Qubit, Bit
from pytket.architecture import Architecture

_known_quil_gate = {
"X": OpType.X,
Expand Down Expand Up @@ -135,15 +135,15 @@ def to_sympy(e: Any) -> Union[float, int, Expr, Symbol]:
+ " cannot be converted to a sympy expression"
)
elif isinstance(e, Add_):
return to_sympy(e.op1) + to_sympy(e.op2) # type: ignore
return to_sympy(e.op1) + to_sympy(e.op2)
elif isinstance(e, Sub):
return to_sympy(e.op1) - to_sympy(e.op2) # type: ignore
return to_sympy(e.op1) - to_sympy(e.op2)
elif isinstance(e, Mul_):
return to_sympy(e.op1) * to_sympy(e.op2) # type: ignore
return to_sympy(e.op1) * to_sympy(e.op2)
elif isinstance(e, Div):
return to_sympy(e.op1) / to_sympy(e.op2) # type: ignore
return to_sympy(e.op1) / to_sympy(e.op2)
elif isinstance(e, Pow_):
return to_sympy(e.op1) ** to_sympy(e.op2) # type: ignore
return to_sympy(e.op1) ** to_sympy(e.op2)
else:
raise NotImplementedError(
"Quil expression could not be converted to a sympy expression: "
Expand All @@ -165,7 +165,7 @@ def pyquil_to_tk(prog: Program) -> Circuit:
tkc = Circuit()
qmap = {}
for q in prog.get_qubits():
uid = Qubit("q", q)
uid = Qubit("q", q) # type: ignore
tkc.add_qubit(uid)
qmap.update({q: uid})
cregmap: Dict = {}
Expand All @@ -178,7 +178,7 @@ def pyquil_to_tk(prog: Program) -> Circuit:
"Operation not supported by tket: " + str(i)
) from error
qubits = [qmap[q.index] for q in i.qubits]
params = [param_from_pyquil(p) for p in i.params] # type: ignore
params: list[Union[Expr, float]] = [param_from_pyquil(p) for p in i.params] # type: ignore
tkc.add_gate(optype, params, qubits)
elif isinstance(i, Measurement):
qubit = qmap[i.qubit.index]
Expand Down Expand Up @@ -237,10 +237,10 @@ def tk_to_pyquil(
"""
p = Program()
qregs = set()
for qb in tkcirc.qubits:
if len(qb.index) != 1:
for qbt in tkcirc.qubits:
if len(qbt.index) != 1:
raise NotImplementedError("PyQuil registers must use a single index")
qregs.add(qb.reg_name)
qregs.add(qbt.reg_name)
if len(qregs) > 1:
raise NotImplementedError(
"Cannot convert circuit with multiple quantum registers to pyQuil"
Expand Down Expand Up @@ -269,24 +269,28 @@ def tk_to_pyquil(
op = command.op
optype = op.type
if optype == OpType.Measure:
qb = Qubit_(command.args[0].index[0])
if qb in measured_qubits:
qbt = Qubit_(command.args[0].index[0]) # type: ignore
if qbt in measured_qubits:
raise NotImplementedError(
"Cannot apply gate on qubit " + qb.__repr__() + " after measurement"
"Cannot apply gate on qubit "
+ qbt.__repr__()
+ " after measurement"
)
bit = command.args[1]
b = cregmap[bit.reg_name][bit.index[0]]
measures.append(Measurement(qb, b))
measured_qubits.append(qb)
b = cregmap[bit.reg_name][bit.index[0]] # type: ignore
measures.append(Measurement(qbt, b)) # type: ignore
measured_qubits.append(qbt)
used_bits.append(bit)
continue
elif optype == OpType.Barrier:
continue # pyQuil cannot handle barriers
qubits = [Qubit_(qb.index[0]) for qb in command.args]
for qb in qubits:
if qb in measured_qubits:
for qbt in qubits: # type: ignore
if qbt in measured_qubits:
raise NotImplementedError(
"Cannot apply gate on qubit " + qb.__repr__() + " after measurement"
"Cannot apply gate on qubit "
+ qbt.__repr__()
+ " after measurement"
)
try:
gatetype = _known_quil_gate_rev[optype]
Expand All @@ -313,7 +317,7 @@ def process_characterisation(qc: QuantumComputer) -> dict:
:return: A dictionary containing Rigetti device characteristics
"""
isa = qc.quantum_processor.to_compiler_isa()
coupling_map = [[int(i) for i in e.ids] for e in isa.edges.values()]
coupling_map = [(int(e.ids[0]), int(e.ids[1])) for e in isa.edges.values()]

str_to_gate_1qb = {
"RX": {
Expand Down Expand Up @@ -395,8 +399,8 @@ def process_characterisation(qc: QuantumComputer) -> dict:

characterisation = dict()
characterisation["NodeErrors"] = node_errors
characterisation["EdgeErrors"] = link_errors
characterisation["Architecture"] = arc
characterisation["EdgeErrors"] = link_errors # type: ignore
characterisation["Architecture"] = arc # type: ignore
characterisation["t1times"] = t1_times_dict
characterisation["t2times"] = t2_times_dict

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
packages=find_namespace_packages(include=["pytket.*"]),
include_package_data=True,
install_requires=[
"pytket ~= 1.17",
"pytket ~= 1.21",
"pyquil ~= 3.5",
"typing-extensions ~= 4.2",
],
Expand Down
6 changes: 3 additions & 3 deletions tests/pyquil_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
MEASURE,
)
from pyquil.quilbase import Measurement
from sympy import pi, Symbol # type: ignore
from sympy import pi, Symbol

from pytket.circuit import Circuit # type: ignore
from pytket.circuit import Circuit
from pytket.extensions.pyquil import pyquil_to_tk, tk_to_pyquil
from pytket.extensions.pyquil import ForestStateBackend
from pytket.passes import RemoveRedundancies # type: ignore
from pytket.passes import RemoveRedundancies

skip_qvm_tests = (which("docker") is None) or (platform.system() == "Windows")

Expand Down
6 changes: 3 additions & 3 deletions tests/qvm_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
ForestStateBackend,
process_characterisation,
)
from pytket.circuit import BasisOrder, Circuit, OpType, Qubit, Node # type: ignore
from pytket.passes import CliffordSimp # type: ignore
from pytket.pauli import Pauli, QubitPauliString # type: ignore
from pytket.circuit import BasisOrder, Circuit, OpType, Qubit, Node
from pytket.passes import CliffordSimp
from pytket.pauli import Pauli, QubitPauliString
from pytket.utils.expectations import (
get_operator_expectation_value,
get_pauli_expectation_value,
Expand Down

0 comments on commit 7735aec

Please sign in to comment.