Skip to content

Commit

Permalink
Merge pull request from GHSA-cq96-9974-v8hm
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
  • Loading branch information
ihincks and kt474 committed Jun 15, 2023
1 parent a750d8c commit 2e8c8c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
6 changes: 2 additions & 4 deletions qiskit_ibm_runtime/options/options.py
Expand Up @@ -135,10 +135,8 @@ def _get_program_inputs(options: dict) -> dict:
}
)
if isinstance(inputs["transpilation_settings"]["coupling_map"], CouplingMap):
inputs["transpilation_settings"][
"coupling_map"
] = eval( # pylint: disable=eval-used
str(inputs["transpilation_settings"]["coupling_map"])
inputs["transpilation_settings"]["coupling_map"] = list(
map(list, inputs["transpilation_settings"]["coupling_map"].get_edges())
)

inputs["resilience_settings"] = options.get("resilience", {})
Expand Down
23 changes: 12 additions & 11 deletions test/unit/test_options.py
Expand Up @@ -189,16 +189,17 @@ def test_init_options_with_dictionary(self):
)

def test_coupling_map_options(self):
"""Check that coupling_map is processed correctly"""
coupling_map = [[1, 0], [2, 1], [0, 1], [1, 2]]
coupling_map_set = {tuple(cp) for cp in coupling_map}
line_coupling_map_set = {tuple(cp) for cp in CouplingMap.from_line(3)}
options_types = [coupling_map_set, line_coupling_map_set]
for opt in options_types:
with self.subTest(opts_dict=opt):
"""Check that coupling_map is processed correctly for various types"""
coupling_map = {(1, 0), (2, 1), (0, 1), (1, 2)}
coupling_maps = [
coupling_map,
list(map(list, coupling_map)),
CouplingMap(coupling_map),
]
for variant in coupling_maps:
with self.subTest(opts_dict=variant):
options = Options()
options.simulator.coupling_map = opt
options.simulator.coupling_map = variant
inputs = Options._get_program_inputs(asdict(options))
input_coupling_map = inputs["transpilation_settings"]["coupling_map"]
inputs_set = {tuple(input) for input in input_coupling_map}
self.assertEqual(inputs_set, opt)
resulting_cmap = inputs["transpilation_settings"]["coupling_map"]
self.assertEqual(coupling_map, set(map(tuple, resulting_cmap)))

0 comments on commit 2e8c8c8

Please sign in to comment.