Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions qiskit/providers/models/backendconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def __init__(self,
max_shots: int,
coupling_map,
n_uchannels: int,
u_channel_lo: List[UchannelLO],
u_channel_lo: List[List[UchannelLO]],
meas_levels: List[int],
qubit_lo_range: List[List[float]],
meas_lo_range: List[List[float]],
Expand Down Expand Up @@ -500,9 +500,15 @@ def from_dict(cls, data):
Returns:
GateConfig: The GateConfig from the input dictionary.
"""
gates = [GateConfig.from_dict(x) for x in data.pop('gates')]
data['gates'] = gates
return cls(**data)
in_data = copy.copy(data)
gates = [GateConfig.from_dict(x) for x in in_data.pop('gates')]
in_data['gates'] = gates
input_uchannels = in_data.pop('u_channel_lo')
u_channels = []
for channel in input_uchannels:
u_channels.append([UchannelLO.from_dict(x) for x in channel])
Comment thread
mtreinish marked this conversation as resolved.
in_data['u_channel_lo'] = u_channels
return cls(**in_data)

def to_dict(self):
"""Return a dictionary format representation of the GateConfig.
Expand All @@ -511,9 +517,15 @@ def to_dict(self):
dict: The dictionary form of the GateConfig.
"""
out_dict = super().to_dict()
u_channel_lo = []
for x in self.u_channel_lo:
channel = []
for y in x:
channel.append(y.to_dict())
u_channel_lo.append(channel)
out_dict.update({
'n_uchannels': self.n_uchannels,
'u_channel_lo': self.u_channel_lo,
'u_channel_lo': u_channel_lo,
'meas_levels': self.meas_levels,
'qubit_lo_range': self.qubit_lo_range,
'meas_lo_range': self.meas_lo_range,
Expand Down
3 changes: 2 additions & 1 deletion qiskit/providers/models/pulsedefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def to_dict(self):
for key, value in self.__dict__.items():
if key not in ['qubit_freq_est', 'meas_freq_est', 'buffer',
'pulse_library', 'cmd_def', 'meas_kernel',
'discriminator']:
'discriminator', 'converter',
'instruction_schedule_map']:
out_dict[key] = value
return out_dict

Expand Down
12 changes: 12 additions & 0 deletions test/python/providers/test_fake_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ def test_to_dict_properties(self, backend):
self.assertIsInstance(backend.properties().to_dict(), dict)
else:
self.assertTrue(backend.configuration().simulator)

@data(*FAKE_PROVIDER.backends())
def test_to_dict_configuration(self, backend):
configuration = backend.configuration()
self.assertIsInstance(configuration.to_dict(), dict)

@data(*FAKE_PROVIDER.backends())
def test_defaults_to_dict(self, backend):
if hasattr(backend, 'defaults'):
self.assertIsInstance(backend.defaults().to_dict(), dict)
else:
self.skipTest('Backend %s does not have defaults' % backend)