-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Qiskit Terra version:
'qiskit-terra': '0.19.1'
'qiskit': '0.33.1' - Python version:
3.9.7 - Operating system:
Windows 10 Pro
What is happening?
I'm trying to implement a Parametric Hadamard Test.
I have already my parametric evolution gate exp(−iθH) where θ is the parameter.
When I defined the controlled-gate with Gate.control(1) and add it to the main circuit. I'm unable to correctly bind the parameters after and I can not get the state vector after the binded circuit.
How can we reproduce the issue?
thetas = ParameterVector('T', length=1)
it = iter(theta)
# Define Hadamard Test
qc = QuantumCircuit(3)
qc.initialize(psi_0, [1,2])
qc.h(0)
# Apply control gate
tr_g_k = tr_g(dt=next(it)) # tr_g is the evolution gate $\exp(-i\theta H)$
tr_g_c = tr_g_k.control(1)
qc.append(tr_g_c, [0,1,2])
qc.h(0)
# --------------------------------------------------------
# Get the StateVector
qc_b = qc.bind_parameters({theta: [np.pi]})
simulator = Aer.get_backend('aer_simulator')
qc_bt = transpile(qc_b, simulator)
qc_bt.save_statevector()
result = simulator.run(qc_bt).result()
statevector = result.get_statevector(qc_bt)
When running the circuit I get:
TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement(T[0])}) cannot be cast to a float.
I have tried without the control, i.e, only the evolution in the qubit 1 and 2 and it works. I think it's because the control, but so far, I have not been able to solve it.
I tried .with the to_matrix() method of CircuitStateFn of Opflow, and I get the same error.
What should happen?
The circuit should bind the parameres correctly and it should give me the statevector at the end.
Any suggestions?
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working