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

Error when drawing circuits generated by StandardRB #9145

Closed
eendebakpt opened this issue Nov 16, 2022 · 6 comments
Closed

Error when drawing circuits generated by StandardRB #9145

eendebakpt opened this issue Nov 16, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@eendebakpt
Copy link
Contributor

Informations

  • Qiskit Experiments version: 0.4.0
  • Python version: 3.10
  • Operating system: Windows

What is the current behavior?

Running this script:

import qiskit
from qiskit_experiments.library import StandardRB
import qiskit_experiments
import numpy as np
print(qiskit.version.QiskitVersion())
print(qiskit_experiments.version.get_version_info())


lengths = np.arange(1, 600, 200)
exp1 = StandardRB([0], lengths, num_samples=4, seed=1010)
circuits=exp1.circuits()
circuits[0].draw()

results in an exception

{'qiskit-terra': '0.22.2', 'qiskit-aer': '0.11.1', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': None, 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
0.4.0

  ...

  File "C:\develop\env310\lib\site-packages\qiskit\visualization\circuit\_utils.py", line 556, in slide_from_left
    if node.op.condition:

AttributeError: 'Clifford' object has no attribute 'condition'

Steps to reproduce the problem

See the minimal example above

What is the expected behavior?

The circuit should be plotted

Suggested solutions

@eendebakpt eendebakpt added the bug Something isn't working label Nov 16, 2022
@conradhaupt
Copy link

conradhaupt commented Nov 16, 2022

I have confirmed that this bug occurs with Qiskit Experiments 0.4.0 and Qiskit Terra 0.22.0 0.22.2 on my Mac. Using the current main of both Qiskit Experiments and Qiskit Terra, I get the output below. Is this the output you would have expected? If yes, then I would say this bug is fixed for the next release.

{'qiskit-terra': '0.23.0', 'qiskit-aer': '0.11.0', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': '0.38.0', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
0.5.0.dev0+d28a4ab
       ░ ┌─────────────────┐ ░ »
   q: ─░─┤ Clifford-1Q(16) ├─░─»
       ░ └─────────────────┘ ░ »
meas: ═════════════════════════»
                               »
«      ┌──────────────────────────────────────────────────────┐ ░ ┌─┐
«   q: ┤ Clifford: Stabilizer = ['-Z'], Destabilizer = ['+Y'] ├─░─┤M├
«      └──────────────────────────────────────────────────────┘ ░ └╥┘
«meas: ════════════════════════════════════════════════════════════╩═
«                                                                    

Edit 2022.11.16 15:42 UTC:

I can confirm that the main version of Qiskit Experiments and Qiskit Terra 0.22.2 works.

{'qiskit-terra': '0.22.2', 'qiskit-aer': None, 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': None, 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}
0.5.0.dev0+338a46d
       ░ ┌─────────────────┐ ░ »
   q: ─░─┤ Clifford-1Q(16) ├─░─»
       ░ └─────────────────┘ ░ »
meas: ═════════════════════════»
                               »
«      ┌──────────────────────────────────────────────────────┐ ░ ┌─┐
«   q: ┤ Clifford: Stabilizer = ['-Z'], Destabilizer = ['+Y'] ├─░─┤M├
«      └──────────────────────────────────────────────────────┘ ░ └╥┘
«meas: ════════════════════════════════════════════════════════════╩═
«                                                                    

@conradhaupt
Copy link

Doing a git bisect from main to 0.4.0 showed that the bug was “fixed” in qiskit-community/qiskit-experiments#898.

@itoko
Copy link
Contributor

itoko commented Nov 16, 2022

This is a bug in Terra. Let's export it as a Terra issue. The following is a minimal code to fail.

from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info.random import random_clifford

circ = QuantumCircuit(1)
circ.append(random_clifford(1), [0])
circ.append(random_clifford(1), [0]) # at least two Clifford objects must be appended
circ.draw()

This error can be avoided by changing Clifford object to Instruction object by random_clifford(1).to_instruction().
That is the reason why the main version of Qiskit Experiments does not fail while the 0.4.0 fails. As @conradhaupt mentioned above, qiskit-community/qiskit-experiments#898 changed to always convert Clifford objects into Instruction objects before appending to a circuit, that results in avoiding the bug.

@conradhaupt
Copy link

@itoko: Ah! That makes sense.

@mtreinish mtreinish transferred this issue from qiskit-community/qiskit-experiments Nov 16, 2022
@1ucian0 1ucian0 self-assigned this Nov 19, 2022
@1ucian0
Copy link
Member

1ucian0 commented Nov 19, 2022

This is related to #9159 as Clifford operations are not instructions.

@1ucian0
Copy link
Member

1ucian0 commented Nov 25, 2022

Fixed by #8907

@1ucian0 1ucian0 closed this as completed Nov 25, 2022
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

No branches or pull requests

4 participants