qiskit-ibm-runtime icon indicating copy to clipboard operation
qiskit-ibm-runtime copied to clipboard

TranspilerError: "The number of qubits for Instruction(name='cx', ...) does not match the number of qubits in the properties dictionary: (0,)"

Open antalszava opened this issue 1 year ago • 6 comments

Information

  • qiskit-ibm-provider version: qiskit-ibm-provider==0.5.2
  • Python version: 3.11
  • Operating system: Ubuntu

What is the current behavior?

When switching from qiskit.IBMQ to IBMProvider as the deprecation message notes an error arises during execution. This can be reproduced simply by querying the target of the obtained backend.

The error:

---------------------------------------------------------------------------
TranspilerError                           Traceback (most recent call last)
Cell In[2], line 35
     32 # ibmq_manhattan supports mid-circuit measurements
     33 backend = provider.get_backend(backend_name)
---> 35 backend.target

File ~/anaconda3/envs/someenv/lib/python3.11/site-packages/qiskit_ibm_provider/ibm_backend.py:329, in IBMBackend.target(self)
    327 self._get_properties()
    328 self._get_defaults()
--> 329 self._convert_to_target()
    330 return self._target

File ~/anaconda3/envs/someenv/lib/python3.11/site-packages/qiskit_ibm_provider/ibm_backend.py:284, in IBMBackend._convert_to_target(self)
    282 """Converts backend configuration, properties and defaults to Target object"""
    283 if not self._target:
--> 284     self._target = convert_to_target(
    285         configuration=self._configuration,
    286         properties=self._properties,
    287         defaults=self._defaults,
    288     )

File ~/anaconda3/envs/someenv/lib/python3.11/site-packages/qiskit_ibm_provider/utils/backend_converter.py:120, in convert_to_target(configuration, properties, defaults)
    118 gate_len = len(gate.coupling_map[0]) if hasattr(gate, "coupling_map") else 0
    119 if name in name_mapping:
--> 120     target.add_instruction(name_mapping[name], gate_props)
    121 else:
    122     custom_gate = Gate(name, gate_len, [])

File ~/anaconda3/envs/someenv/lib/python3.11/site-packages/qiskit/transpiler/target.py:381, in Target.add_instruction(self, instruction, properties, name)
    379 for qarg in properties:
    380     if qarg is not None and len(qarg) != instruction.num_qubits:
--> 381         raise TranspilerError(
    382             f"The number of qubits for {instruction} does not match the number "
    383             f"of qubits in the properties dictionary: {qarg}"
    384         )
    385     if qarg is not None:
    386         self.num_qubits = max(self.num_qubits, max(qarg) + 1)

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

from qiskit_ibm_provider import IBMProvider
backend_name = 'simulator_extended_stabilizer'
provider = IBMProvider(token='<Token here>')

# ibmq_manhattan supports mid-circuit measurements
backend = provider.get_backend(backend_name)
backend.target

What is the expected behavior?

No error.

Suggested solutions

antalszava avatar May 03 '23 10:05 antalszava

Hi @kt474 @merav-aharoni any update on this?

It seems like the best solution, for now, is to keep using the deprecated qiskit.IBMQ module. When would functionality from there be removed completely? This would be helpful to know so that things don't start breaking unexpectedly.

antalszava avatar May 25 '23 11:05 antalszava

There is an issue with the configuration/coupling map for simulator_extended_stabilizer - I will get it prioritized in the appropriate team

kt474 avatar May 25 '23 15:05 kt474

Note that "simulator_stabilizer" is also affected.

antalszava avatar May 31 '23 16:05 antalszava

Hi @kt474, any updates on this?

antalszava avatar Oct 27 '23 15:10 antalszava

I can confirm this still affects 0.7.3

from qiskit import transpile, QuantumCircuit
from qiskit_ibm_provider import IBMProvider

provider = IBMProvider()
backend = provider.get_backend('simulator_stabilizer')
qc = QuantumCircuit()
transpile(qc, backend)
---------------------------------------------------------------------------
TranspilerError                           Traceback (most recent call last)
<ipython-input-9-01fb77e621f3> in <module>
      1 backend = provider.get_backend('simulator_stabilizer')
      2 qc = QuantumCircuit()
----> 3 transpile(qc, backend)

/qiskit/compiler/transpiler.py in transpile(circuits, backend, basis_gates, inst_map, coupling_map, backend_properties, initial_layout, layout_method, routing_method, translation_method, scheduling_method, instruction_durations, dt, approximation_degree, timing_constraints, seed_transpiler, optimization_level, callback, output_name, unitary_synthesis_method, unitary_synthesis_plugin_config, target, hls_config, init_method, optimization_method, ignore_backend_supplied_default_methods)
    324         _skip_target = True
    325     else:
--> 326         target = getattr(backend, "target", None)
    327 
    328     initial_layout = _parse_initial_layout(initial_layout)

.../qiskit_ibm_provider/ibm_backend.py in target(self)
    320             Target
    321         """
--> 322         return self._get_target()
    323 
    324     def target_history(self, datetime: Optional[python_datetime] = None) -> Target:

.../qiskit_ibm_provider/ibm_backend.py in _get_target(self, datetime, refresh)
    272             api_properties = client.backend_properties(self.name, datetime=datetime)
    273             api_pulse_defaults = client.backend_pulse_defaults(self.name)
--> 274             target = target_from_server_data(
    275                 configuration=self._configuration,
    276                 pulse_defaults=api_pulse_defaults,

.../qiskit_ibm_provider/utils/json_decoder.py in target_from_server_data(configuration, pulse_defaults, properties)
    268             )
    269         else:
--> 270             target.add_instruction(
    271                 instruction=inst_name_map[inst_name],
    272                 properties=prop_name_map.get(inst_name, None),

.../qiskit/transpiler/target.py in add_instruction(self, instruction, properties, name)
    428             for qarg in properties:
    429                 if qarg is not None and len(qarg) != instruction.num_qubits:
--> 430                     raise TranspilerError(
    431                         f"The number of qubits for {instruction} does not match the number "
    432                         f"of qubits in the properties dictionary: {qarg}"

TranspilerError: "The number of qubits for Instruction(name='cy', num_qubits=2, num_clbits=0, params=[]) does not match the number of qubits in the properties dictionary: (0,)"

1ucian0 avatar Dec 14 '23 11:12 1ucian0

@1ucian0 This needs to be fixed on the server side - there is an issue open (ntc 2451), we need to get the right backend configurations

kt474 avatar Dec 14 '23 16:12 kt474