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

TypeError when using Qiskit plugin to convert circuit with a ParameterExpression #198

Open
Vivekyy opened this issue Sep 26, 2023 · 4 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Vivekyy
Copy link
Contributor

Vivekyy commented Sep 26, 2023

Getting the following TypeError when attempting to utilize the Qiskit plugin to convert a Qiskit circuit containing a ParameterExpression:

TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement(θ[0])}) cannot be cast to a float.

Code to reproduce the error:

from qiskit.circuit.library import RealAmplitudes
from torchquantum.plugins import qiskit2tq

ansatz = RealAmplitudes(2, reps=1)
tq_layer = qiskit2tq(ansatz)
@GenericP3rson
Copy link
Collaborator

Hey! Thanks for pointing this out! As of now, we can't yet directly convert ParameterVectorElement to TQ. (I can see about creating a quick workaround if you'd like!) However, for this specific example, we do have a TQ version of RealAmplitudes recently merged which can be accessed like a layer.

class RealAmplitudes(TwoLocal):

@GenericP3rson GenericP3rson added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers enhancement New feature or request labels Oct 15, 2023
@GenericP3rson
Copy link
Collaborator

Marking this issue so we can get to it more thoroughly. The main idea would be to add Parameter/ParameterVector/etc. support for the tq2qiskit operation.

@Vivekyy
Copy link
Contributor Author

Vivekyy commented Oct 15, 2023

Would be great to get a fix for this! Our application is predeminantly dealing with passing torchquantum a custom transpiled circuit, so it may need for this fix to be done.

@Vivekyy
Copy link
Contributor Author

Vivekyy commented Oct 17, 2023

As a note, a temporary workaround for this issue is to just bind parameters before passing a circuit into qiskit2tq. I'm not sure if this is sufficient for a general fix, but it does work for our case at least.

Seperately, I ran into a bug that occurs when layouts are unchanged during transpilation. This was an easier fix, so I'll make a quick pull request for that.

@GenericP3rson GenericP3rson self-assigned this Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants