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

Transpiling fails if the target does not specify properties for measurement instructions #8969

Closed
hay-k opened this issue Oct 20, 2022 · 0 comments · Fixed by #8995
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hay-k
Copy link
Contributor

hay-k commented Oct 20, 2022

Environment

  • Qiskit Terra version: 0.22.0
  • Python version: 3.9.12
  • Operating system: Windows 10

What is happening?

Traceback (most recent call last):
  File ".\src\playground.py", line 86, in <module>
    qc_transpiled = transpile(qc, target=target)
  File ".\lib\site-packages\qiskit\compiler\transpiler.py", line 327, in transpile
    unique_transpile_args, shared_args = _parse_transpile_args(
  File ".\lib\site-packages\qiskit\compiler\transpiler.py", line 646, in _parse_transpile_args
    backend_properties = target_to_backend_properties(target)
  File ".\lib\site-packages\qiskit\transpiler\target.py", line 1021, in target_to_backend_properties
    if props.error is not None:
AttributeError: 'NoneType' object has no attribute 'error'

How can we reproduce the issue?

When building a transpiler target, the properties for added instructions are optional. The documentation of qiskit.transpiler.Target.add_instruction says Properties are optional for any instruction implementation, if there are no InstructionProperties available for the backend the value can be None.. However, it seems this claim is true for all instructions except measurement.

The below code snippet shows how to construct a very simple target with one qubit and measurement instruction associated with it. The measurement instruction does not have any properties (i.e. it is specified as None). Then, this target is used to transpile a circuit, which results into the error pasted above

from qiskit import QuantumCircuit
from qiskit.circuit.library import Measure
from qiskit.compiler import transpile
from qiskit.transpiler import Target

target = Target()
target.add_instruction(Measure(), {(0,): None})

qc = QuantumCircuit(1, 1)
qc.measure(0, 0)

transpile(qc, target=target)

What should happen?

The transpilation should not fail

Any suggestions?

No response

@hay-k hay-k added the bug Something isn't working label Oct 20, 2022
@mtreinish mtreinish added this to the 0.22.1 milestone Oct 25, 2022
@mtreinish mtreinish self-assigned this Oct 25, 2022
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Oct 25, 2022
This commit fixes an oversight in the transpile() function when running
with a Target (either directly or via a backend) that contains a
Measurement operation that is ideal (either globally or locally) with no
properties defined. This was not handled correctly in the function used
to convert a Target to a BackendProperties payload for passes that are
not yet target aware and this would cause an exception to be raised.
This commit fixes this edge case and excludes readout properties from
the generated BackendProperties in this case.

Fixes Qiskit#8969
@mergify mergify bot closed this as completed in #8995 Oct 28, 2022
mergify bot added a commit that referenced this issue Oct 28, 2022
This commit fixes an oversight in the transpile() function when running
with a Target (either directly or via a backend) that contains a
Measurement operation that is ideal (either globally or locally) with no
properties defined. This was not handled correctly in the function used
to convert a Target to a BackendProperties payload for passes that are
not yet target aware and this would cause an exception to be raised.
This commit fixes this edge case and excludes readout properties from
the generated BackendProperties in this case.

Fixes #8969

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this issue Oct 28, 2022
This commit fixes an oversight in the transpile() function when running
with a Target (either directly or via a backend) that contains a
Measurement operation that is ideal (either globally or locally) with no
properties defined. This was not handled correctly in the function used
to convert a Target to a BackendProperties payload for passes that are
not yet target aware and this would cause an exception to be raised.
This commit fixes this edge case and excludes readout properties from
the generated BackendProperties in this case.

Fixes #8969

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 72ba2ee)
mergify bot added a commit that referenced this issue Oct 28, 2022
)

This commit fixes an oversight in the transpile() function when running
with a Target (either directly or via a backend) that contains a
Measurement operation that is ideal (either globally or locally) with no
properties defined. This was not handled correctly in the function used
to convert a Target to a BackendProperties payload for passes that are
not yet target aware and this would cause an exception to be raised.
This commit fixes this edge case and excludes readout properties from
the generated BackendProperties in this case.

Fixes #8969

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

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
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.

2 participants