@@ -73,22 +73,25 @@ def __init__(
73
73
coupling_map : Optional [List [List [int ]]] = None ,
74
74
control_channel_map : Optional [Dict [Tuple [int , ...], List [ControlChannel ]]] = None ,
75
75
library : Optional [Union [BasisGateLibrary , List [BasisGateLibrary ]]] = None ,
76
+ libraries : Optional [List [BasisGateLibrary ]] = None ,
76
77
add_parameter_defaults : bool = True ,
77
78
backend_name : Optional [str ] = None ,
78
79
backend_version : Optional [str ] = None ,
79
80
):
80
81
"""Initialize the calibrations.
81
82
82
- Calibrations can be initialized from a basis gate library , i.e. a subclass of
83
+ Calibrations can be initialized from a list of basis gate libraries , i.e. a subclass of
83
84
:class:`BasisGateLibrary`. As example consider the following code:
84
85
85
86
.. code-block:: python
86
87
87
88
cals = Calibrations(
88
- library=FixedFrequencyTransmon(
89
- basis_gates=["x", "sx"],
90
- default_values={duration: 320}
91
- )
89
+ libraries=[
90
+ FixedFrequencyTransmon(
91
+ basis_gates=["x", "sx"],
92
+ default_values={duration: 320}
93
+ )
94
+ ]
92
95
)
93
96
94
97
Args:
@@ -99,27 +102,41 @@ def __init__(
99
102
keys are tuples of qubits and the values are a list of ControlChannels
100
103
that correspond to the qubits in the keys. If a control_channel_map is given
101
104
then the qubits must be in the coupling_map.
102
- library: A library instance from which to get template schedules to register as well
103
- as default parameter values.
105
+ library (deprecated): A library instance from which to get template schedules to
106
+ register as well as default parameter values.
107
+ libraries: A list of library instance from which to get template schedules to register
108
+ as well as default parameter values.
104
109
add_parameter_defaults: A boolean to indicate weather the default parameter values of
105
- the given library should be used to populate the calibrations. By default this
110
+ the given libraries should be used to populate the calibrations. By default this
106
111
value is True but can be set to false when deserializing a calibrations object.
107
112
backend_name: The name of the backend that these calibrations are attached to.
108
113
backend_version: The version of the backend that these calibrations are attached to.
109
114
110
115
Raises:
111
- NotImplementedError: if a list of libraries is given. This will be implemented in
112
- the future.
116
+ CalibrationError: if both library and libraries are given. Note that library will be
117
+ removed in future versions.
118
+
113
119
"""
114
120
self ._backend_name = backend_name
115
121
self ._backend_version = backend_version
116
122
117
- if isinstance (library , list ):
118
- raise NotImplementedError (
119
- "Passing a list of libraries from which to instantiate "
120
- "will be supported in future releases."
123
+ if library :
124
+ warnings .warn (
125
+ "library has been deprecated, please provide `libraries` instead."
126
+ "The `library` argument along with this warning will be removed "
127
+ "in Qiskit Experiments 0.4." ,
128
+ DeprecationWarning ,
129
+ stacklevel = 2 ,
121
130
)
122
131
132
+ if libraries :
133
+ raise CalibrationError ("Cannot supply both library and libraries." )
134
+
135
+ if not isinstance (library , list ):
136
+ libraries = [library ]
137
+ else :
138
+ libraries = library
139
+
123
140
# Mapping between qubits and their control channels.
124
141
self ._control_channel_map = control_channel_map if control_channel_map else {}
125
142
@@ -149,18 +166,18 @@ def __init__(
149
166
self ._hash_to_counter_map = {}
150
167
self ._parameter_counter = 0
151
168
152
- self ._library = None
153
- if library is not None :
154
- self . _library = library
169
+ self ._libraries = libraries
170
+ if libraries is not None :
171
+ for lib in libraries :
155
172
156
- # Add the basis gates
157
- for gate in library .basis_gates :
158
- self .add_schedule (library [gate ], num_qubits = library .num_qubits (gate ))
173
+ # Add the basis gates
174
+ for gate in lib .basis_gates :
175
+ self .add_schedule (lib [gate ], num_qubits = lib .num_qubits (gate ))
159
176
160
- # Add the default values
161
- if add_parameter_defaults :
162
- for param_conf in library .default_values ():
163
- self .add_parameter_value (* param_conf , update_inst_map = False )
177
+ # Add the default values
178
+ if add_parameter_defaults :
179
+ for param_conf in lib .default_values ():
180
+ self .add_parameter_value (* param_conf , update_inst_map = False )
164
181
165
182
# This internal parameter is False so that if a schedule is added after the
166
183
# init it will be set to True and serialization will raise an error.
@@ -220,6 +237,7 @@ def from_backend(
220
237
cls ,
221
238
backend : Backend ,
222
239
library : Optional [BasisGateLibrary ] = None ,
240
+ libraries : Optional [List [BasisGateLibrary ]] = None ,
223
241
add_parameter_defaults : bool = True ,
224
242
) -> "Calibrations" :
225
243
"""Create an instance of Calibrations from a backend.
@@ -228,8 +246,10 @@ def from_backend(
228
246
backend: A backend instance from which to extract the qubit and readout frequencies
229
247
(which will be added as first guesses for the corresponding parameters) as well
230
248
as the coupling map.
231
- library: A library instance from which to get template schedules to register as well
232
- as default parameter values.
249
+ library: A library or list thereof from which to get template schedules to register as
250
+ well as default parameter values.
251
+ libraries: A list of libraries from which to get template schedules to register as
252
+ well as default parameter values.
233
253
add_parameter_defaults: A boolean to indicate whether the default parameter values of
234
254
the given library should be used to populate the calibrations. By default this
235
255
value is ``True``.
@@ -246,6 +266,7 @@ def from_backend(
246
266
getattr (backend .configuration (), "coupling_map" , []),
247
267
getattr (backend .configuration (), "control_channels" , None ),
248
268
library ,
269
+ libraries ,
249
270
add_parameter_defaults ,
250
271
backend_name ,
251
272
getattr (backend , "version" , None ),
@@ -264,9 +285,20 @@ def from_backend(
264
285
return cals
265
286
266
287
@property
267
- def library (self ) -> Optional [BasisGateLibrary ]:
268
- """Return the name of the library, e.g. for experiment metadata."""
269
- return self ._library
288
+ def libraries (self ) -> Optional [List [BasisGateLibrary ]]:
289
+ """Return the libraries used to initialize the calibrations."""
290
+ return self ._libraries
291
+
292
+ @property
293
+ def library (self ) -> Optional [List [BasisGateLibrary ]]:
294
+ """Return the libraries used to initialize the calibrations."""
295
+ warnings .warn (
296
+ "library has been deprecated, use libraries instead."
297
+ "This warning will be removed with backport in Qiskit Experiments 0.4." ,
298
+ DeprecationWarning ,
299
+ stacklevel = 2 ,
300
+ )
301
+ return self ._libraries
270
302
271
303
def _get_operated_qubits (self ) -> Dict [int , List [int ]]:
272
304
"""Get a dict describing qubit couplings.
@@ -1609,7 +1641,7 @@ def __eq__(self, other: "Calibrations") -> bool:
1609
1641
- The backends have the same name.
1610
1642
- The backends have the same version.
1611
1643
- The calibrations contain the same schedules.
1612
- - The stored paramters have the same values.
1644
+ - The stored parameters have the same values.
1613
1645
"""
1614
1646
if self .backend_name != other .backend_name :
1615
1647
return False
@@ -1654,7 +1686,7 @@ def config(self) -> Dict[str, Any]:
1654
1686
kwargs = {
1655
1687
"coupling_map" : self ._coupling_map ,
1656
1688
"control_channel_map" : ControlChannelMap (self ._control_channel_map ),
1657
- "library " : self .library ,
1689
+ "libraries " : self .libraries ,
1658
1690
"add_parameter_defaults" : False , # the parameters will be added outside of the init
1659
1691
"backend_name" : self ._backend_name ,
1660
1692
"backend_version" : self ._backend_version ,
0 commit comments