Skip to content

parameters in RXXGate #10697

@Muzhou-Ma

Description

@Muzhou-Ma

Environment

python version 3.10.11

What is happening?

I'm trying to give RXXGate a parameter phi when I encounter this error:
ParameterExpression with unbound parameters ({Parameter(a)}) cannot be cast to a float.

Here is my codes:

phi = Parameter('a')
qc = QuantumCircuit(4)
a = RXXGate(phi).control(2)
qc = qc.compose(a)
qc.draw()

However, it's interesting that everything works fine if the control method isn't used:

phi_1 = Parameter('a')
qc = QuantumCircuit(4)
a = RXXGate(theta = phi_1)
qc = qc.compose(a, [2, 3])
qc.draw()

which can give the result:

q_0: ───────────
                
q_1: ───────────
     ┌─────────┐
q_2: ┤0        ├
     │  Rxx(a) │
q_3: ┤1        ├
     └─────────┘

I'm wondering what I've done wrong and how to fix it?

Besides, is it possible for me to make this parameter trainable for optimization tasks like using gradient descend?

How can we reproduce the issue?

Perhaps making the Parameter class more flexible can help.

What should happen?

I suppose the gate should take this parameter and give it a random(or zero) initialization.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions