Skip to content

Commit

Permalink
[infra] Update to qiskit 0.45 and qiskit-ibm-runtime 0.14. (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Nov 14, 2023
1 parent 45b42d3 commit e2981d8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
5 changes: 3 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ unreleased
----------

* Add support for circuits with barriers in the Aer simulators.
* Update qiskit version to 0.44.3.
* Update qiskit-ibm-runtime version to 0.13.0.
* Update qiskit version to 0.45.0.
* Update qiskit-ibm-runtime version to 0.14.0.
* Update qiskit-aer version to 0.13.0.
* Update qiskit-ibm-provider version to 0.7.2.
* Introduce dependency on qiskit-algorithms.
* Seed given to ``process_circuits()`` will be automatically incremented
for the different circuit batches submitted.
Expand Down
38 changes: 23 additions & 15 deletions pytket/extensions/qiskit/qiskit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@
ParameterExpression,
Reset,
)
from qiskit.circuit.library import CRYGate, RYGate, PauliEvolutionGate, StatePreparation

from qiskit.extensions.unitary import UnitaryGate # type: ignore
from qiskit.extensions import Initialize # type: ignore
from qiskit.circuit.library import (
CRYGate,
RYGate,
PauliEvolutionGate,
StatePreparation,
UnitaryGate,
Initialize,
)
from pytket.circuit import (
CircBox,
Circuit,
Expand Down Expand Up @@ -354,18 +358,18 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None:
self.add_xs(num_ctrl_qubits, ctrl_state, qargs)
optype = None
if isinstance(instr, ControlledGate):
if type(instr) in _known_qiskit_gate:
if instr.base_class in _known_qiskit_gate:
# First we check if the gate is in _known_qiskit_gate
# this avoids CZ being converted to CnZ
optype = _known_qiskit_gate[type(instr)]
elif type(instr.base_gate) == qiskit_gates.RYGate:
optype = _known_qiskit_gate[instr.base_class]
elif instr.base_gate.base_class is qiskit_gates.RYGate:
optype = OpType.CnRy
elif type(instr.base_gate) == qiskit_gates.YGate:
elif instr.base_gate.base_class is qiskit_gates.YGate:
optype = OpType.CnY
elif type(instr.base_gate) == qiskit_gates.ZGate:
elif instr.base_gate.base_class is qiskit_gates.ZGate:
optype = OpType.CnZ
else:
if type(instr.base_gate) in _known_qiskit_gate:
if instr.base_gate.base_class in _known_qiskit_gate:
optype = OpType.QControlBox # QControlBox case handled below
else:
raise NotImplementedError(
Expand All @@ -376,7 +380,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None:
pass # Special handling below
else:
try:
optype = _known_qiskit_gate[type(instr)]
optype = _known_qiskit_gate[instr.base_class]
except KeyError:
raise NotImplementedError(
f"Conversion of qiskit's {instr.name} instruction is "
Expand All @@ -388,7 +392,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None:
bits = [self.cbmap[bit] for bit in cargs]

if optype == OpType.QControlBox:
base_tket_gate = _known_qiskit_gate[type(instr.base_gate)]
base_tket_gate = _known_qiskit_gate[instr.base_gate.base_class]
params = [param_to_tk(p) for p in instr.base_gate.params]
n_base_qubits = instr.base_gate.num_qubits
sub_circ = Circuit(n_base_qubits)
Expand Down Expand Up @@ -822,9 +826,13 @@ def tk_to_qiskit(
for p in qcirc.parameters:
name_spl = p.name.split("_UUID:", 2)
if len(name_spl) == 2:
p_name, uuid = name_spl
new_p = Parameter.__new__(Parameter, p_name, UUID(uuid))
new_p.__init__(p_name)
p_name, uuid_str = name_spl
uuid = UUID(uuid_str)
# See Parameter.__init__() in qiskit/circuit/parameter.py.
new_p = Parameter(p_name)
new_p._uuid = uuid
new_p._parameter_keys = frozenset(((p_name, uuid),))
new_p._hash = hash((new_p._parameter_keys, new_p._symbol_expr))
updates[p] = new_p
qcirc.assign_parameters(updates, inplace=True)

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
include_package_data=True,
install_requires=[
"pytket ~= 1.21",
"qiskit ~= 0.44.3",
"qiskit ~= 0.45.0",
"qiskit-algorithms ~= 0.2.1",
"qiskit-ibm-runtime ~= 0.13.0",
"qiskit-ibm-runtime ~= 0.14.0",
"qiskit-aer ~= 0.13.0",
"qiskit-ibm-provider ~= 0.7.0",
"qiskit-ibm-provider ~= 0.7.2",
"numpy",
],
classifiers=[
Expand Down
8 changes: 6 additions & 2 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,12 @@ def test_rebase_phase() -> None:


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
def test_postprocess(lagos_backend: IBMQBackend) -> None:
b = lagos_backend
def test_postprocess() -> None:
b = IBMQBackend(
"ibm_lagos",
instance="ibm-q/open/main",
token=os.getenv("PYTKET_REMOTE_QISKIT_TOKEN"),
)
assert b.supports_contextual_optimisation
c = Circuit(2, 2)
c.SX(0).SX(1).CX(0, 1).measure_all()
Expand Down
15 changes: 8 additions & 7 deletions tests/qiskit_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
)
from qiskit.quantum_info import Pauli, SparsePauliOp # type: ignore
from qiskit.transpiler import PassManager # type: ignore
from qiskit.circuit.library import RYGate, MCMT, XXPlusYYGate, PauliEvolutionGate # type: ignore
from qiskit.circuit.library import RYGate, MCMT, XXPlusYYGate, PauliEvolutionGate, UnitaryGate # type: ignore
import qiskit.circuit.library.standard_gates as qiskit_gates # type: ignore
from qiskit.circuit import Parameter
from qiskit.synthesis import SuzukiTrotter # type: ignore
from qiskit_aer import Aer # type: ignore
from qiskit.quantum_info import Statevector
from qiskit.extensions import UnitaryGate # type: ignore

from pytket.circuit import (
Circuit,
Expand Down Expand Up @@ -117,9 +116,9 @@ def get_test_circuit(measure: bool, reset: bool = True) -> QuantumCircuit:
qc.cy(qr[0], qr[1])
qc.cz(qr[1], qr[2])
qc.ecr(qr[0], qr[1])
qc.i(qr[2])
qc.id(qr[2])
qc.iswap(qr[3], qr[0])
qc.mct([qr[0], qr[1], qr[2]], qr[3])
qc.mcx([qr[0], qr[1], qr[2]], qr[3])
qc.mcx([qr[1], qr[2], qr[3]], qr[0])
qc.p(pi / 4, qr[1])
qc.r(pi / 5, pi / 6, qr[2])
Expand Down Expand Up @@ -716,14 +715,16 @@ def test_parameter_equality() -> None:
circ.cx(0, 1)
# fails with preserve_param_uuid=False
# as Parameter uuid attribute is not preserved
# and so fails equality check at bind_parameters
# and so fails equality check at assign_parameters
pytket_circ = qiskit_to_tk(circ, preserve_param_uuid=True)
final_circ = tk_to_qiskit(pytket_circ)

assert final_circ.parameters == circ.parameters

param_dict = dict(zip([param_a, param_b], [1, 2]))
final_circ.bind_parameters(param_dict)
final_circ.assign_parameters(param_dict, inplace=True)

assert final_circ.parameters == circ.parameters
assert len(final_circ.parameters) == 0


# https://github.com/CQCL/pytket-extensions/issues/275
Expand Down

0 comments on commit e2981d8

Please sign in to comment.