goodchemistryco / Tangelo

A python package for exploring end-to-end chemistry workflows on quantum computers and simulators.
https://goodchemistryco.github.io/Tangelo/
Other
99 stars 27 forks source link

Support for multi-controlled rotation (RX, RY, RZ) gates for qiskit backend #387

Closed ValentinS4t1qbit closed 1 month ago

ValentinS4t1qbit commented 1 month ago

Issue: Feature Request

We recently went to a hackathon, and participants wanted to solve a challenge using a circuit with multi-controlled Ry gates. They wanted to translate the Tangelo circuit to Qiskit to simulate a fake IBM device or transpile to IBM native gate set, but got a NotImplemented error from Tangelo.

Indeed, we had written that function before Qiskit implemented multi-controlled gates, but Qiskit later supported them: here's the mcry gate https://docs.quantum.ibm.com/api/qiskit/0.43/qiskit.circuit.QuantumCircuit#mcry.

Can you modify https://github.com/ValentinS4t1qbit/Tangelo/blob/main/tangelo/linq/translator/translate_qiskit.py so that multi-controlled gates (CRX, CRY, CRZ) are supported in the translation from Tangelo to Qiskit and remove the error message ? (e.g, a list on integers can be passed for control qubits).

It may be that the crx, cry and crz gates in Qiskit can simply be seen as mcrx, mcry and mcrz with only one control qubit, which may help us resolve things elegantly with very little changes.

Test

Making this snippet work for CRY is a good starting point:

from tangelo.linq import Gate, Circuit, translate_circuit, get_backend

# Defines a multi-controlled RY gate in tangelo
c = Circuit([Gate('CRY', 2, control=[0,1], parameter=1.)])
c_qiskit = translate_circuit(c, target="qiskit")  # should not return an error

# Qiskit seems to parse this as a sequence of gate
print(c_qiskit)

You should see that Qiskit parses that gate into this:

Screenshot 2024-05-25 at 11 52 58 PM

To solve this issue:

golanor commented 1 month ago

Hi, I've submitted a PR to address this, but I'm unsure if I should base on main or develop. What should I do?

alexfleury-sb commented 1 month ago

Hello @golanor, first of all, thank you! We target the develop branch for PRs. This should be an easy switch as both main and develop are synchronized at the moment.

golanor commented 1 month ago

Thanks! It seems that the branches are not synced right now - develop is 10 commits behind main.

alexfleury-sb commented 1 month ago

Oh you are right, this happens when a release is made, so there are commits for README and other files not related to the code. The code itself should be the same, either way I suggest to target develop.

ValentinS4t1qbit commented 1 month ago

Closed by @golanor @390