-
Notifications
You must be signed in to change notification settings - Fork 22
/
ionq.py
90 lines (81 loc) · 2.61 KB
/
ionq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2023 qBraid
#
# This file is part of the qBraid-SDK
#
# The qBraid-SDK is free software released under the GNU General Public License v3
# or later. You can redistribute and/or modify it under the terms of the GPL v3.
# See the LICENSE file in the project root or <https://www.gnu.org/licenses/gpl-3.0.html>.
#
# THERE IS NO WARRANTY for the qBraid-SDK, as per Section 15 of the GPL v3.
"""
Module defining Utility functions to be able to run IonQ device from AWS
"""
import pytket
import pytket.extensions.braket
from braket.circuits import Circuit
from pytket._tket.circuit._library import _TK1_to_RzRx # type: ignore
from pytket.passes import RebaseCustom
from pytket.predicates import (
CompilationUnit,
GateSetPredicate,
MaxNQubitsPredicate,
NoClassicalControlPredicate,
NoFastFeedforwardPredicate,
NoMidMeasurePredicate,
NoSymbolsPredicate,
)
HARMONY_MAX_QUBITS = 11
ionq_gates = {
pytket.circuit.OpType.X,
pytket.circuit.OpType.Y,
pytket.circuit.OpType.Z,
pytket.circuit.OpType.Rx,
pytket.circuit.OpType.Ry,
pytket.circuit.OpType.Rz,
pytket.circuit.OpType.H,
pytket.circuit.OpType.S,
pytket.circuit.OpType.Sdg,
pytket.circuit.OpType.T,
pytket.circuit.OpType.Tdg,
pytket.circuit.OpType.V,
pytket.circuit.OpType.Vdg,
pytket.circuit.OpType.Measure,
pytket.circuit.OpType.noop,
pytket.circuit.OpType.SWAP,
pytket.circuit.OpType.CX,
pytket.circuit.OpType.ZZPhase,
pytket.circuit.OpType.XXPhase,
pytket.circuit.OpType.YYPhase,
pytket.circuit.OpType.ZZMax,
pytket.circuit.OpType.Barrier,
}
preds = [
NoClassicalControlPredicate(),
NoFastFeedforwardPredicate(),
NoMidMeasurePredicate(),
NoSymbolsPredicate(),
GateSetPredicate(ionq_gates),
MaxNQubitsPredicate(HARMONY_MAX_QUBITS),
]
ionq_rebase_pass = RebaseCustom(
ionq_gates,
pytket.Circuit(), # cx_replacement (irrelevant)
_TK1_to_RzRx,
) # tk1_replacement
def braket_ionq_compilation(circuit) -> Circuit:
"""
Compiles a Braket circuit to a Braket circuit that can run on IonQ Harmony.
Args:
circuit (Circuit): The input Braket circuit to be compiled.
Returns:
Circuit: The compiled Braket circuit that can run on IonQ Harmony.
"""
if isinstance(circuit, Circuit):
tk_circuit = pytket.extensions.braket.braket_convert.braket_to_tk(circuit)
else:
tk_circuit = circuit
cu = CompilationUnit(tk_circuit, preds)
ionq_rebase_pass.apply(cu)
assert cu.check_all_predicates()
compiled, _, _ = pytket.extensions.braket.braket_convert.tk_to_braket(cu.circuit)
return compiled