C2QA / bosonic-qiskit

Extension of Qiskit to support hybrid boson-qubit simulations for the NQI C2QA effort.
BSD 2-Clause "Simplified" License
46 stars 11 forks source link

Parameterized circuits in c2qa-qiskit #39

Closed teaguetomesh closed 2 years ago

teaguetomesh commented 2 years ago

Hi @tjstavenger-pnnl, I was just talking with @EllaCrane and she mentioned that you are looking into adding support for Parameterized circuits in c2qa-qiskit. Just yesterday I had tested whether this was possible but ran into a TypeError: unsupported operand type(s) for ** or pow(): 'Parameter' and 'int'.

I'm opening this issue to provide the small example from our use case that reproduces the error, if it is any help to you.

numberofqubits=2
numberofmodes=3
numberofqubitspermode=2

qmr = c2qa.QumodeRegister(num_qumodes=numberofmodes, num_qubits_per_qumode=numberofqubitspermode)
qbr = qiskit.QuantumRegister(size=numberofqubits)
cbr = qiskit.ClassicalRegister(size=1) # To read out the results of the Hadamard test
circuit = c2qa.CVCircuit(qmr, qbr, cbr)

phi = qiskit.circuit.Parameter('phi')
circuit.cv_rh1(phi, qmr[0], qmr[1], qbr[0])
tjstavenger-pnnl commented 2 years ago

I have a version working of parameterized circuits, but testing needs to be done to see if it is what you'd expect. @kevincsmith is interested in it too. See https://github.com/C2QA/c2qa-qiskit/pull/47 for the current PR into main.

tjstavenger-pnnl commented 2 years ago

I merged into main this morning. Can you see how it works for you and your needs?

tjstavenger-pnnl commented 2 years ago

We've found an error in the current implementation that improperly calculates the number of qiskit qubits used by our parameterized gates. I have a new PR started to correct that: https://github.com/C2QA/c2qa-qiskit/pull/51

tjstavenger-pnnl commented 2 years ago

@kevincsmith has confirmed our implementation works with his VQE effort. I'll close this issue for now. If there are coding changes needed or errors found, please let us know.