Hi Team. I’m using pennylane for measuring some quantum states. However, it’s too slow to measure, since I want to get the measurement under different parameters of the circuit. I didn’t find helpful demos in docs, and I’m not familiar with some packages like jit
or jax
. So I wish to use multiprocess to achieve a speedup by using multiple CPUs since I do not have a GPU. I’m wondering whether qml.QNode supports it? Do I need to init a QNode in each process, like the following code?
def main(n_process):
processes = []
for i in range(n_process):
p = mp.Process(target=measurePorb_basic_process, args=(
...# some arguments for measureProb_basic_process
))
processes.append(p)
p.start()
for p in processes:
p.join()
def measurePorb_basic_process():
qnode = qml.QNode(circuit, device=qml.device("default.qubit", wires=2, shots=100)) # take 2 bit 100 shots for example
measurements = qnode(args) # get the measurements, suppose it returns qml.Sample(...)
# do some postprocessing for `measurements` variable
...
def circuit(args): # define a circuit
qml.RX(args, wires=0)
qml.CNOT(wires=[0,1])
return [qml.sample(qml.PauliZ(i)) for i in range(2)]
Or, I just define the QNode out of measureProb_basic_process
function, i.e., define it in main function? Thanks for your time.