pasqal-io / qadence

Digital-analog quantum programming interface
https://pasqal-io.github.io/qadence/latest/
Apache License 2.0
66 stars 21 forks source link

Multi-controlled gates and Sqrt(X) gate #194

Closed hsinyuryanwu closed 9 months ago

hsinyuryanwu commented 9 months ago

Hi Qadence team,

Would it be possible to add these two functions?

  1. The Multicontrol X(NOT) gate.

For example, MCX([0,2,3,4], 1, controlled type), where the controlled type is [|1>,|1>,|1>,|1>] by default. It would be great if the users can arbitrarily change it to [|1>,|0>,|0>,|1>] for MCRX, MCRZ and MCX functions.

  1. Sqrt(X) gate. https://qiskit.org/documentation/stubs/qiskit.circuit.library.SXGate.html

We need their dagger (adjoint) version as well.

Thanks, Hsin-Yu

AnniePaine commented 9 months ago

Multicontrol X seems to be implemented as Toffoli (it allows general number of controls) however when I go to use it as

import qadence as qd
qd.Toffoli((1,2,3,), 4)

I get the error message
module 'qadence' has no attribute 'Toffoli'

This method of calling other gates has worked so not sure why not for Toffoli. My only thought is I have noticed that Toffoli is not included in all of operations.py.

Any help in using Toffoli is appreciated!

hsinyuryanwu commented 9 months ago

Only MCZ is provided. display(MCZ([0,1,3], 2)) However, what we need is MCX.

madagra commented 9 months ago

Thanks @AnniePaine and @hsinyuryanwu for reporting this bug and feature request.

madagra commented 9 months ago

Toffoli((1,2,3,), 4)

Indeed, it seems that the Toffoli gate is not properly exported. I opened a PR to fix this: https://github.com/pasqal-io/qadence/pull/195.

For the usage of Toffoli gate, recall that the Python indexing system starts from 0. The following should work:

import qadence as qd

block = qd.chain(
    qd.X(0),
    qd.operations.Toffoli((0,1,2), 3)
)

samples = qd.sample(block)
madagra commented 9 months ago

Only MCZ is provided. display(MCZ([0,1,3], 2)) However, what we need is MCX.

The MCRX operation for multi-qubit controlled rotation is available. Does this work for you? The Sqrt(X) gate is indeed currently missing, I will add the corresponding issue.

hsinyuryanwu commented 9 months ago

Hi Madagra,

display(qd.operations.Toffoli((0,1,3), 2))

Could we just use qd.Toffoli without "operations" sandwitched between them?

nmheim commented 9 months ago

Hey @hsinyuryanwu, we just released qadence v1.1.0 which contains the qd.Toffoli fix, so if you

pip install --upgrade qadence

you should be able to leave out the operations.

I will close this issue, because the Sqrt gate is tracked here. Let us know if you find/need anything else!