Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generating preset pass manager for simulators fails #8546

Closed
kevinsung opened this issue Aug 15, 2022 · 2 comments · Fixed by #9719
Closed

generating preset pass manager for simulators fails #8546

kevinsung opened this issue Aug 15, 2022 · 2 comments · Fixed by #9719
Labels
bug Something isn't working

Comments

@kevinsung
Copy link
Contributor

kevinsung commented Aug 15, 2022

Environment

  • Qiskit Terra version: 0.21.1
  • Python version: 3.9.13
  • Operating system: Arch Linux

What is happening?

generating preset pass manager for ibmq_qasm_simulator fails

How can we reproduce the issue?

from qiskit import IBMQ
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q-internal', group='deployed', project='default')
backend = provider.get_backend("ibmq_qasm_simulator")
pass_manager = generate_preset_pass_manager(optimization_level=0, backend=backend)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [2], in <cell line: 7>()
      5 provider = IBMQ.get_provider(hub='ibm-q-internal', group='deployed', project='default')
      6 backend = provider.get_backend("ibmq_qasm_simulator")
----> 7 pass_manager = generate_preset_pass_manager(optimization_level=0, backend=backend)

File /usr/local/venvs/low-rank-qdrift-278at_FA/lib/python3.9/site-packages/qiskit/transpiler/preset_passmanagers/__init__.py:178, in generate_preset_pass_manager(optimization_level, backend, target, basis_gates, inst_map, coupling_map, instruction_durations, backend_properties, timing_constraints, initial_layout, layout_method, routing_method, translation_method, scheduling_method, approximation_degree, seed_transpiler, unitary_synthesis_method, unitary_synthesis_plugin_config)
    158 pm_options = dict(
    159     target=target,
    160     basis_gates=basis_gates,
   (...)
    174     initial_layout=initial_layout,
    175 )
    177 if backend is not None:
--> 178     pm_config = PassManagerConfig.from_backend(backend, **pm_options)
    179 else:
    180     pm_config = PassManagerConfig(**pm_options)

File /usr/local/venvs/low-rank-qdrift-278at_FA/lib/python3.9/site-packages/qiskit/transpiler/passmanager_config.py:123, in PassManagerConfig.from_backend(cls, backend, **pass_manager_options)
    121 if backend_version < 2:
    122     if hasattr(backend, "defaults"):
--> 123         res.inst_map = backend.defaults().instruction_schedule_map
    124 else:
    125     res.inst_map = backend.instruction_schedule_map

AttributeError: 'NoneType' object has no attribute 'instruction_schedule_map'

What should happen?

It shouldn't throw an error.

Any suggestions?

No response

@kevinsung kevinsung added the bug Something isn't working label Aug 15, 2022
@kevinsung
Copy link
Contributor Author

Same issue with AerSimulator backend. I think that the code should be able to handle being passed a simulator. Of course optimization is not as important with a simulator, but just having it be handled would be a nice convenience.

@kevinsung
Copy link
Contributor Author

With BasicAer you still get an error, but it's different.

from qiskit import BasicAer
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

backend = BasicAer.get_backend("statevector_simulator")
pass_manager = generate_preset_pass_manager(optimization_level=0, backend=backend)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [2], in <cell line: 5>()
      2 from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
      4 backend = BasicAer.get_backend("statevector_simulator")
----> 5 pass_manager = generate_preset_pass_manager(optimization_level=0, backend=backend)

File ~/projects/qiskit-terra/qiskit/transpiler/preset_passmanagers/__init__.py:178, in generate_preset_pass_manager(optimization_level, backend, target, basis_gates, inst_map, coupling_map, instruction_durations, backend_properties, timing_constraints, initial_layout, layout_method, routing_method, translation_method, scheduling_method, approximation_degree, seed_transpiler, unitary_synthesis_method, unitary_synthesis_plugin_config)
    158 pm_options = dict(
    159     target=target,
    160     basis_gates=basis_gates,
   (...)
    174     initial_layout=initial_layout,
    175 )
    177 if backend is not None:
--> 178     pm_config = PassManagerConfig.from_backend(backend, **pm_options)
    179 else:
    180     pm_config = PassManagerConfig(**pm_options)

File ~/projects/qiskit-terra/qiskit/transpiler/passmanager_config.py:133, in PassManagerConfig.from_backend(cls, backend, **pass_manager_options)
    131 if res.instruction_durations is None:
    132     if backend_version < 2:
--> 133         res.instruction_durations = InstructionDurations.from_backend(backend)
    134     else:
    135         res.instruction_durations = backend.instruction_durations

File ~/projects/qiskit-terra/qiskit/transpiler/instruction_durations.py:77, in InstructionDurations.from_backend(cls, backend)
     75 # All durations in seconds in gate_length
     76 instruction_durations = []
---> 77 for gate, insts in backend.properties()._gates.items():
     78     for qubits, props in insts.items():
     79         if "gate_length" in props:

AttributeError: 'NoneType' object has no attribute '_gates'

@kevinsung kevinsung changed the title generating preset pass manager for ibmq_qasm_simulator fails generating preset pass manager for simulators fails Aug 16, 2022
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Mar 3, 2023
This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes Qiskit#8546
Fixes Qiskit#9265
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Mar 3, 2023
This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes Qiskit#8546
Fixes Qiskit#9265
@mergify mergify bot closed this as completed in #9719 Mar 3, 2023
mergify bot added a commit that referenced this issue Mar 3, 2023
#9719)

This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes #8546
Fixes #9265

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this issue Mar 3, 2023
#9719)

This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes #8546
Fixes #9265

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 35feded)
mergify bot added a commit that referenced this issue Mar 4, 2023
#9719) (#9725)

This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes #8546
Fixes #9265

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 35feded)

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this issue May 22, 2023
Qiskit#9719)

This commit fixes two small oversights that would appear when calling
PassManagerConfig.from_backend() with a simulator BackendV1 backend.
The handling of optional fields in the BackendProperties and
PulseDefaults objects for BackendV1 backends was missing that a
BackendProperties object's gates field could be None and that the
defaults() method could return None in the absense of any pulse
calibrations (both of which typically only are True for simulators). In
these cases this would cause an error constructing the
InstructionDurations object and the InstructionScheduleMap object
respectively. This fixes the handling of these edge cases so that
PassManagerConfig.from_backend() will work with any BackendV1 based
backend.

Fixes Qiskit#8546
Fixes Qiskit#9265

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant