Skip to content

hybrid computing with batch #1269

Discussion options

You must be logged in to vote

Hi @WeiyinchiangFu,

For batched inputs, a typical workflow is this:

import cudaq 
from cudaq import spin 
import numpy as np 
qubit_count = 1 
hamiltonian = spin.z(0)
num_of_samples = 4 
num_of_params = 2
theta_vals = np.random.rand(num_of_samples, num_of_params)

kernel, thetas = cudaq.make_kernel(list)

qubits = kernel.qalloc(qubit_count)

kernel.ry(thetas[0], qubits[0])
kernel.rx(thetas[1], qubits[0])

results = cudaq.observe(kernel, hamiltonian, theta_vals)
for i in range(len(results)): 
    print(results[i].expectation())

Here we are batching over the num_of_samples. The final for loop is required and can't be avoided.

The observe call is where the execution of the quantum circui…

Replies: 7 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by WeiyinchiangFu
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@WeiyinchiangFu
Comment options

Comment options

You must be logged in to vote
1 reply
@zohimchandani
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants