NVIDIA/cuda-quantum

How to add Global Phase gate to CUDAQ kernels

ACE07-Sev opened this issue · 2 comments

Greetings there,

Hope all are well. I would like to know how I can add a global phase gate. I initially wanted to do this by adding its unitary matrix form, but since that is not currently supported, I'd like to know how I can add it with the current 0.7.x releases.

Hi @ACE07-Sev,

Global phase rotation can be accommodated by the custom unitary matrix gate feature (upcoming 0.8 release) or by using a gate decomposition.

The latter leveraged the fact that r1 and rz gates (CUDA-Q supported gates) are equivalent up to a global phase.
Here is a simple example demonstrating that:

import cudaq
import math

@cudaq.kernel
def global_phase(theta: float):
    # Global phase e(i*theta) == r1(2*theta) * rz(-2*theta)
    qubit = cudaq.qubit()
    # make it |0> + |1>
    h(qubit)
    rz(-2*theta, qubit)
    r1(2*theta, qubit)

# Global phase of pi == multiply the state by -1
state = cudaq.get_state(global_phase, math.pi)
print(state) # expect (-(|0> + |1>))

Closing this as this is now supported with the custom unitaries feature.