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

Transpiler service alters circuit parameter names #47

Open
jyu00 opened this issue Aug 23, 2024 · 5 comments
Open

Transpiler service alters circuit parameter names #47

jyu00 opened this issue Aug 23, 2024 · 5 comments

Comments

@jyu00
Copy link

jyu00 commented Aug 23, 2024

Circuit returned by the transpiler service has its parameter names altered. For example:

from qiskit.circuit.library import RealAmplitudes
from qiskit_transpiler_service.transpiler_service import TranspilerService

circuit = RealAmplitudes(num_qubits=2, reps=1)
print(f"Before parameters: {circuit.parameters}")

transpiler = TranspilerService(backend_name="ibmq_manila", optimization_level=1)
isa_circ = transpiler.run(circuit)
print(f"After parameters: {isa_circ.parameters}")

This prints

Before parameters: ParameterView([ParameterVectorElement(θ[0]), ParameterVectorElement(θ[1]), ParameterVectorElement(θ[2]), ParameterVectorElement(θ[3])])

After parameters: ParameterView([Parameter(_θ_0_), Parameter(_θ_1_), Parameter(_θ_2_), Parameter(_θ_3_)])
@jyu00
Copy link
Author

jyu00 commented Aug 23, 2024

A workaround is to have a mapping of the before/after parameter names using they position. For example, one can track that parameter θ[0] is at position 0. So any parameter values that were supposed to go to θ[0] will now go to the new position 0 parameter named _θ_0_

@y4izus
Copy link
Collaborator

y4izus commented Aug 26, 2024

Thank you for submitting the issue @jyu00 ! Since it belongs to our internal repo instead of this one, I will create the issue there and close this one, ok?

@jyu00
Copy link
Author

jyu00 commented Aug 26, 2024

I opened this issue here so other people who encounter the same issue can see the progress. For that reason, I'd prefer to leave this open until it's fixed.

@victor-villar
Copy link
Collaborator

Hi @jyu00 ! I've been checking and this seems to be a problem with the QASM3 importer/exporter. If I just serialize to qasm3 and deserialize again, without doing anything else in between, the same problem arises:

from qiskit.circuit.library import RealAmplitudes

circuit = RealAmplitudes(num_qubits=2, reps=1)
print(f"Before parameters: {circuit.parameters}")

circuit_q = qasm3.loads(qasm3.dumps(circuit))
print(f"After parameters: {circuit_q.parameters}")

This prints:

Before parameters: ParameterView([ParameterVectorElement(θ[0]), ParameterVectorElement(θ[1]), ParameterVectorElement(θ[2]), ParameterVectorElement(θ[3])])
After parameters: ParameterView([Parameter(_θ_0_), Parameter(_θ_1_), Parameter(_θ_2_), Parameter(_θ_3_)])

@jesus-talavera-ibm
Copy link
Contributor

Hi @jyu00, can you check if this issue is still happening in last version? We started using QPY as exchange format with service, so QASM3 bug should not appear anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants