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

Simulators incorrectly contain coupling map for gates leading to pickling error #512

Closed
ashsaki opened this issue Feb 15, 2023 · 1 comment
Labels
type: bug Something isn't working

Comments

@ashsaki
Copy link

ashsaki commented Feb 15, 2023

Information

  • qiskit-ibm-provider version: 0.2.1
  • Python version: 3.9.13
  • Operating system: Ubuntu 22.04 64 bit (VMWare virtual machine on Win10 host)

What is the current behavior?

Simulators fetched from the new IBMProvider() contains coupling map for gates.

Simulators should not have coupling map for gates. Moreover, the coupling maps are incorrect at times. For example, the simulator_extended_stabilizer has 2-qubit cx gate with single-qubit coupling where as 1-qubit id gate has multi-qubit couplings.

# From new IBMProvider()
Backend name simulator_extended_stabilizer
Gate name u1
    Coupling map [[0], [1], [2], [3], [4]]
Gate name cx
    Coupling map [[0], [1], [2], [3], [4]]
Gate name cz
    Coupling map [[0], [1], [2], [3], [4]]
Gate name id
    Coupling map [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]]
Gate name x
Gate name y
Gate name z
Gate name h
Gate name s
Gate name sdg
Gate name sx
Gate name t
Gate name tdg
Gate name swap
Gate name p
Gate name ccx
Gate name ccz
Gate name delay

On the other hand, simulator backends fetched using previous IBMQ does not have couplings for gates.

# From previous IBMQ
Backend name simulator_extended_stabilizer
Gate name u0
Gate name u1
Gate name cx
Gate name cz
Gate name id
Gate name x
Gate name y
Gate name z
Gate name h
Gate name s
Gate name sdg
Gate name sx
Gate name t
Gate name tdg
Gate name swap
Gate name p
Gate name ccx
Gate name ccz
Gate name delay
Gate name roerror

The incorrect gate couplings leads to pickling error when I try to pickle.dump() a backend from new IBMProvider().

Code Snippet

hw = provider.get_backend(name='ibm_nairobi')
print(hw)
with open('backend.pkl', 'wb') as pf:
    pickle.dump(hw ,pf)

Error traceback

+++ backend name simulator_extended_stabilizer +++
name u1 gate coupling map [[0], [1], [2], [3], [4]]
name cx gate coupling map [[0], [1], [2], [3], [4]]
gate name cx gate props {(0,): None, (1,): None, (2,): None, (3,): None, (4,): None}
Traceback (most recent call last):
  File <>, in <module>
    pickle.dump(hw ,pf)
  File "/home/saki/anaconda3/envs/qiskit/lib/python3.9/site-packages/qiskit_ibm_provider/ibm_backend.py", line 243, in __getattr__
    self._convert_to_target()
  File "/home/saki/anaconda3/envs/qiskit/lib/python3.9/site-packages/qiskit_ibm_provider/ibm_backend.py", line 280, in _convert_to_target
    self._target = convert_to_target(
  File "/home/saki/anaconda3/envs/qiskit/lib/python3.9/site-packages/qiskit_ibm_provider/utils/backend_converter.py", line 116, in convert_to_target
    target.add_instruction(name_mapping[name], gate_props)
  File "/home/saki/anaconda3/envs/qiskit/lib/python3.9/site-packages/qiskit/transpiler/target.py", line 374, in add_instruction
    raise TranspilerError(
qiskit.transpiler.exceptions.TranspilerError: "The number of qubits for Instruction(name='cx', num_qubits=2, num_clbits=0, params=[]) does not match the number of qubits in the properties dictionary: (0,)"

Steps to reproduce the problem

The following is a minimum working example to reproduce the error:

import pickle
from qiskit_ibm_provider import IBMProvider
from qiskit import IBMQ


TOKEN = "<insert your token>"


print("+++++++++++++++++++++++++++++++++++++++++++++++++++")

provider = IBMQ.enable_account(TOKEN)
sim = provider.get_backend('simulator_extended_stabilizer')
print(f"Backend name {sim.configuration().backend_name}")
for gate in sim.configuration().gates:
    print(f"Gate name {gate.name}")
    if hasattr(gate, "coupling_map"):
        print(f"    Coupling map {gate.coupling_map}")

print("+++++++++++++++++++++++++++++++++++++++++++++++++++")

hub = 'ibm-q'
group = 'open'
project = 'main'
provider = IBMProvider(TOKEN, instance=f"{hub}/{group}/{project}")
sim = provider.get_backend('simulator_extended_stabilizer')
print(f"Backend name {sim.configuration().backend_name}")
for gate in sim.configuration().gates:
    print(f"Gate name {gate.name}")
    if hasattr(gate, "coupling_map"):
        print(f"    Coupling map {gate.coupling_map}")

print("+++++++++++++++++++++++++++++++++++++++++++++++++++")

hw = provider.get_backend(name='ibm_nairobi')
print(hw)
with open('backend.pkl', 'wb') as pf:
    pickle.dump(hw ,pf)

What is the expected behavior?

The expected behaviors are:

  • No coupling map for gates from simulators.
  • No error while pickling a backend object.

Suggested solutions

The source, from where the simulator backends are fetching their configurations, must be updated so that it mimics old but correct behavior for coupling map of simulator gates.

@ashsaki ashsaki added the type: bug Something isn't working label Feb 15, 2023
@kt474
Copy link
Member

kt474 commented Feb 16, 2023

Another inconsistency between backends - related to #511

@drew-distefano drew-distefano closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 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