Skip to content

CUDA-Q

Classiq to CUDA-Q translation. These functions require the cudaq extra (install classiq[cudaq]). Note that the cudaq extra is only available in Classiq Studio and on any Linux Machine.

qprog_to_cudaq_kernel

qprog_to_cudaq_kernel(
    quantum_program: QuantumProgram,
    is_main_kernel: bool = True,
) -> Union[PyKernel, tuple]

Translates a quantum program into a CUDA-Q kernel.

The 'is_main_kernel' parameter controls the kind of the returned kernel. If 'is_main_kernel' is True, the returned kernel can be used with CUDA-Q functions such as 'cudaq.draw()' and 'cudaq.get_state()', but it cannot be added to another kernel via `apply_call()'. If 'is_main_kernel' is False, the reverse holds: The returned kernel cannot be used with CUDA-Q functions but can be added to another kernel.

Parameters:

Name Type Description Default
quantum_program QuantumProgram

The quantum program to translate into CUDA-Q kernel. This is the result of the function 'synthesize()'.

required
is_main_kernel bool

Whether the kernel is compatible with CUDA-Q functions (is_main_kernel=True, the default behavior) or 'apply_call()' (is_main_kernel=False)

True

Returns:

Type Description
Union[PyKernel, tuple]

A CUDA-Q kernel. If the quantum program includes foreach statements, a tuple

Union[PyKernel, tuple]

containing a CUDA-Q kernel and its foreach arguments will be returned.

Examples:

Simulating a kernel with is_main_kernel=True:

@qfunc
def main(x: CReal, q: Output[QBit]) -> None:
    allocate(q)
    RX(x, q)


qprog = synthesize(main)
kernel = qprog_to_cudaq_kernel(qprog, is_main_kernel=True)
result = cudaq.get_state(kernel, math.pi / 2)

Adding the kernel to another kernel with is_main_kernel=False:

@qfunc
def main(x: CReal, q: Output[QBit]) -> None:
    allocate(q)
    RX(x, q)


qprog = synthesize(main)
kernel = qprog_to_cudaq_kernel(qprog, is_main_kernel=False)
other_kernel = cudaq.make_kernel()
reg = other_kernel.qalloc(1)
other_kernel.apply_call(kernel, math.pi, reg[0])

pauli_operator_to_cudaq_spin_op

pauli_operator_to_cudaq_spin_op(
    operator: SparsePauliOp,
) -> SpinOperator

Transforms Qmod's SparsePauliOp data structure to CUDA-Q's SpinOperator.

Parameters:

Name Type Description Default
operator SparsePauliOp

The operator to be transformed

required

Returns:

Name Type Description
SpinOperator SpinOperator

The equivalent operator in CUDA-Q's data structure