Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

backend.coupling_map.make_symmetric() requires account reload to undo #486

Closed
nonhermitian opened this issue Jan 26, 2023 · 2 comments
Closed
Labels
type: bug Something isn't working

Comments

@nonhermitian
Copy link
Contributor

Information

  • qiskit-ibm-provider version: latest
  • Python version:
  • Operating system:

What is the current behavior?

backend = provider.get_backend('ibm_sherbrooke')
print(backend.coupling_map.is_symmetric)
backend.coupling_map.make_symmetric()
print(backend.coupling_map.is_symmetric)
backend = provider.get_backend('ibm_sherbrooke')
print(backend.coupling_map.is_symmetric)

Shows that backend.coupling_map.make_symmetric() modifies the coupling_map of the backend in the provider in-place, and cannot be undone without reloading the account.

Steps to reproduce the problem

Run above

What is the expected behavior?

The coupling_map for the instance is modified, but I should be able to make a new instance that does not have the same changes to it.

Suggested solutions

Make a copy of the coupling map (and perhaps other items) when grabbing a backend from the provider.

@nonhermitian nonhermitian added the type: bug Something isn't working label Jan 26, 2023
@kt474 kt474 added this to the 0.5.0 milestone Mar 5, 2023
@mtreinish
Copy link
Member

This could be considered an issue with terra. The behavior of backend.coupling_map is inherited from the abstract base class (https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/providers/backend.py#L387-L390) which automatically generates the object by calling backend.target.build_coupling_map() which builds a coupling map from the Target object. Because depending on the size of the device this repeated cost can be expensive because it has to iterate over all the instructions reported (gate + qubits) on a target the Target caches it's output https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/transpiler/target.py#L911-L920 The provider can override this but any backend will exhibit this behavior.

That being said I'm not sure expecting inplace mutation of a coupling map attribute on a single backend instance would be sticky like that (it'd be the same as mutating a list attribute on an object). However, I think the crux of the issue here is that the provider is caching the backend instances. Because in the OP I would expect initializing a new backend with get_backend() a second time would be a fresh instance and wouldn't be reusing the Target between instances.

@kt474
Copy link
Member

kt474 commented Nov 30, 2023

I believe this has been resolved, closing

@kt474 kt474 closed this as completed Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants