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

transpile() always returns a circuit not in a list whether or not the input is a circuit in a list #5260

Closed
wmurphy-collabstar opened this issue Oct 19, 2020 · 3 comments · Fixed by #5298
Labels
bug Something isn't working status: pending PR It has one or more PRs pending to solve this issue

Comments

@wmurphy-collabstar
Copy link
Contributor

Information

  • Qiskit Terra version:
  • Python version:
  • Operating system:

What is the current behavior?

When you run transpile function with a circuit list of only one circuit, then the output is the circuit, not the circuit in a list.

Steps to reproduce the problem

from qiskit import *
new_qc = transpile([qc], backend) #for some circuit qc and backend
new_qc

What is the expected behavior?

Right now, new_qc would produce a circuit not in a list, but I think it would be helpful if it would result as a list.

Suggested solutions

One suggested solution is to make a new variable in the transpile function called list_boolean, or something else, which would keep track of whether the input is a list or not, and in the conditional where the input list is length 1, one can check the value of list_boolean and if it is true, it returns the transpiled circuit in a list, and if false, it just returns the circuit.

@wmurphy-collabstar wmurphy-collabstar added the bug Something isn't working label Oct 19, 2020
@1ucian0
Copy link
Member

1ucian0 commented Oct 21, 2020

It seems to me the current behavior is intentional:
https://github.com/Qiskit/qiskit-terra/blob/397320a8faff018cc9e338aed98d2d73e33a5b54/qiskit/compiler/transpile.py#L200-L206

However, I agree with you that it is counterintuitive. Fixing it is kind of trivial. But maybe we should try to understand deeper why it is currently like this. @ajavadia @kdk ?

@kdk
Copy link
Member

kdk commented Oct 26, 2020

From #2166, it looks like the intent was to support both

transpiled_qc = transpile(qc, backend)

and

[transpiled_qc1, transpiled_qc2, ...] = transpile([qc1, qc2, ...], backend)

so I think returning a length-1 list for a length-1 list input is consistent.

@1ucian0
Copy link
Member

1ucian0 commented Oct 26, 2020

I think the problem is that transpiled_qc = transpile([qc], backend) instead of [transpiled_qc] = transpile([qc], backend)

@1ucian0 1ucian0 added the status: pending PR It has one or more PRs pending to solve this issue label Oct 29, 2020
@mergify mergify bot closed this as completed in #5298 Nov 13, 2020
airwoodix added a commit to airwoodix/qiskit-terra that referenced this issue Mar 20, 2023
1ucian0 pushed a commit that referenced this issue Apr 2, 2023
* PassManager.run: preserve input signature for length 1 list

Closes #9798

* test/transpiler: consolidate regression tests for #5260 and #9798
ElePT pushed a commit to ElePT/qiskit that referenced this issue Apr 5, 2023
)

* PassManager.run: preserve input signature for length 1 list

Closes Qiskit#9798

* test/transpiler: consolidate regression tests for Qiskit#5260 and Qiskit#9798
giacomoRanieri pushed a commit to giacomoRanieri/qiskit-terra that referenced this issue Apr 16, 2023
)

* PassManager.run: preserve input signature for length 1 list

Closes Qiskit#9798

* test/transpiler: consolidate regression tests for Qiskit#5260 and Qiskit#9798
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this issue May 22, 2023
)

* PassManager.run: preserve input signature for length 1 list

Closes Qiskit#9798

* test/transpiler: consolidate regression tests for Qiskit#5260 and Qiskit#9798
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status: pending PR It has one or more PRs pending to solve this issue
Projects
None yet
3 participants