Hi all ,
i am trying to run Grover’s algorithm (see below for a implementation) multithreaded in an arm node with 32GB 48 cores. I was expecting to be able to run it for 30 qubits. However, i am noticing that memory at some point goes beyond 32GB and crashes. Can you help me figure it out ?
Btw neither qml.probs() nor qml.probs() work analytically . However, through shots qml.probs() is able to run with small shot budget though.
Thank you ![]()
import pennylane as qml
import numpy as np
import os
os.environ["OMP_NUM_THREADS"] = "48"
os.environ["OMP_PROC_BIND"] = "true"
os.environ["OMP_PLACES"] = "cores"
from argparse import ArgumentParser
# ---- Args ----
parser = ArgumentParser()
parser.add_argument("--n_qubits", type=int, default=1, help="Number of qubits")
args = parser.parse_args()
# ---- Parameters ----
NUM_QUBITS = args.n_qubits
omega = np.array([np.ones(NUM_QUBITS)])
M = len(omega)
N = 2**NUM_QUBITS
wires = list(range(NUM_QUBITS))
dev = qml.device("lightning.kokkos", wires=NUM_QUBITS)#, shots = 10**9)
@qml.qnode(dev)
def circuit():
#iterations = int(np.round(np.sqrt(N / M) * np.pi / 4))
iterations = 10
# Initial state preparation
for w in wires:
qml.Hadamard(wires=w)
# Grover's iterator
for _ in range(iterations):
for omg in omega:
qml.FlipSign(omg, wires=wires)
qml.templates.GroverOperator(wires)
return qml.probs(wires=wires)
if __name__ == "__main__":
probs = circuit()
print(f"Probabilities for {NUM_QUBITS} qubits: {probs}")
