4
4
from qibo .backends import Backend
5
5
from qibo .transpiler .pipeline import Passes
6
6
from qibo .transpiler .unroller import NativeGates , Unroller
7
+ from qibolab import PulseSequence
7
8
from qibolab ._core .compilers import Compiler
9
+ from qibolab ._core .native import NativeContainer
8
10
9
11
from qibocal .auto .operation import QubitId
10
12
@@ -109,29 +111,35 @@ def execute_transpiled_circuit(
109
111
)
110
112
111
113
112
- def natives (platform ):
114
+ def natives (platform ) -> dict [ str , NativeContainer ] :
113
115
"""
114
- Return the list of native gates defined in the `platform`.
115
- This function assumes the native gates to be the same for each
116
+ Return the dict of native gates name with the associated native container
117
+ defined in the `platform`. This function assumes the native gates to be the same for each
116
118
qubit and pair.
117
119
"""
118
120
pair = next (iter (platform .pairs ))
119
121
qubit = next (iter (platform .qubits ))
120
- two_qubit_natives = list (platform .natives .two_qubit [pair ].model_fields )
121
- single_qubit_natives = list (platform .natives .single_qubit [qubit ].model_fields )
122
+ two_qubit_natives_container = platform .natives .two_qubit [pair ]
123
+ single_qubit_natives_container = platform .natives .single_qubit [qubit ]
124
+ single_qubit_natives = list (single_qubit_natives_container .model_fields )
125
+ two_qubit_natives = list (two_qubit_natives_container .model_fields )
122
126
# Solve Qibo-Qibolab mismatch
123
127
single_qubit_natives .append ("RZ" )
124
128
single_qubit_natives .append ("Z" )
125
129
single_qubit_natives .remove ("RX12" )
126
130
single_qubit_natives .remove ("RX90" )
127
131
single_qubit_natives .remove ("CP" )
128
- new_single_natives = [REPLACEMENTS .get (i , i ) for i in single_qubit_natives ]
129
- return new_single_natives + two_qubit_natives
132
+ single_qubit_natives = [REPLACEMENTS .get (x , x ) for x in single_qubit_natives ]
133
+ return {i : platform .natives .single_qubit [qubit ] for i in single_qubit_natives } | {
134
+ i : platform .natives .two_qubit [pair ] for i in two_qubit_natives
135
+ }
130
136
131
137
132
- def create_rule (native ):
133
- def rule (gate , native ):
134
- return native .ensure (gate .__class__ .__name__ ).create_sequence ()
138
+ def create_rule (name , natives ):
139
+ """Create rule for gate name given container natives."""
140
+
141
+ def rule (gate : gates .Gate , natives : NativeContainer ) -> PulseSequence :
142
+ return natives .ensure (name ).create_sequence ()
135
143
136
144
return rule
137
145
@@ -142,10 +150,10 @@ def set_compiler(backend, natives_):
142
150
"""
143
151
compiler = backend .compiler
144
152
rules = {}
145
- for native in natives_ :
146
- gate = getattr (gates , native )
153
+ for name , natives_container in natives_ . items () :
154
+ gate = getattr (gates , name )
147
155
if gate not in compiler .rules :
148
- rules [gate ] = create_rule (native )
156
+ rules [gate ] = create_rule (name , natives_container )
149
157
else :
150
158
rules [gate ] = compiler .rules [gate ]
151
159
rules [gates .I ] = compiler .rules [gates .I ]
0 commit comments