Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CUDA-Q kernels for CircuitToEinsum #141

Open
zohimchandani opened this issue Jun 15, 2024 · 4 comments
Open

Support CUDA-Q kernels for CircuitToEinsum #141

zohimchandani opened this issue Jun 15, 2024 · 4 comments

Comments

@zohimchandani
Copy link

For an upcoming demo, we need cuQuantum to accept CUDA-Q circuits into the CircuitToEinsum function here.

Here is an example of how to do this in Qiskit:

from cuquantum import cutensornet as cutn
from cuquantum import contract, CircuitToEinsum
import torch 
from qiskit.circuit import QuantumCircuit, Parameter

num_qubits = 1
measurement_ops = 'Z'
light_cone  = True 

# Define the quantum circuit with one qubit and two parameters
theta = Parameter('θ')
phi = Parameter('φ')

circuit = QuantumCircuit(num_qubits)
circuit.rx(theta, 0)
circuit.ry(phi, 0)

parameters = [1,2]
    
circuit = circuit.bind_parameters({theta: parameters[0], phi: parameters[1]})

converter = CircuitToEinsum(circuit, backend='torch')  

einsum_expression, tensor_operands = converter.expectation(measurement_ops, light_cone)

Note that you have to provide a bound circuit (circuit with values supplied for the variational gates).

It would be nice if we could support CircuitToEinsum to take in variational circuits that are unbound but I'm guessing that the einsum expression will look different for different parameter values and hence this is not feasible?

In CUDA-Q, the corresponding code looks like this:

import cudaq
from typing import List

cudaq.set_target("nvidia")

@cudaq.kernel
def kernel(angles: List[float]):
    qubit = cudaq.qubit()
    rx(angles[0], qubit)
    ry(angles[1], qubit)


hamiltonian = cudaq.spin.z(0)

parameters = [1, 2]

expectation_value = cudaq.observe(kernel, hamiltonian, parameters).expectation()

Note how the binding of the parameters happens in the observe call. How do we deal with this? @1tnguyen @bettinaheim

@bettinaheim
Copy link

bettinaheim commented Jun 17, 2024 via email

@zohimchandani
Copy link
Author

Demo is scheduled for 15th August, we need to give this feature to our collaborators so that they can implement the workflow ahead of this. Thanks team.

@fmozafari
Copy link

@bettinaheim @zohimchandani In circuitToEinsum we go over a circuit object and extract a sequence of gates with their matrix representations and qubits that act on. We tried to add cudaq but seems there is not explicit python API to get the matrices. Even we can not directly get the gate names and it is required to parse strings from kernel.to_qir(). Is it possible to add this functionality to get the matrix for each gate?

@zohimchandani
Copy link
Author

@bettinaheim pinging as a reminder, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants