Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Fixed
"""""

- Fixed incorrect parsing of some API hub URLs (#77).
- Fixed noise model handling for remote simulators (#84).


`0.1.1`_ - 2019-05-01
Expand Down
32 changes: 30 additions & 2 deletions qiskit/providers/ibmq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@
from qiskit.qobj import QobjHeader


def _serialize_noise_model(config):
"""Traverse the dictionary looking for noise_model keys and apply
a transformation so it can be serialized.

Args:
config (dict): The dictionary to traverse

Returns:
dict: The transformed dictionary
"""
for k, v in config.items():
if isinstance(config[k], dict):
_serialize_noise_model(config[k])
else:
if k == 'noise_model':
try:
config[k] = v.as_dict(serializable=True)
except AttributeError:
# if .as_dict() fails is probably because the noise_model
# has been already transformed elsewhere
pass

return config


def update_qobj_config(qobj, backend_options=None, noise_model=None):
"""Update a Qobj configuration from options and noise model.

Expand All @@ -35,9 +60,12 @@ def update_qobj_config(qobj, backend_options=None, noise_model=None):
for key, val in backend_options.items():
config[key] = val

# Append noise model to configuration.
# Append noise model to configuration. Overwrites backend option
if noise_model:
config['noise_model'] = noise_model.as_dict(serializable=True)
config['noise_model'] = noise_model

# Look for noise_models in the config, and try to transform them
config = _serialize_noise_model(config)

# Update the Qobj configuration.
qobj.config = QobjHeader.from_dict(config)
Expand Down