Hello World

Hello, World!

This guide will show you how to run a simple qiskit program in a Qubernetes cluster using the GPU infrastructure.

Create a new program

program.py
from qiskit import QuantumCircuit, transpile
from qiskit_aer import Aer, AerSimulator
 
def demo_function(shotsAmount=1000):
    simulator = AerSimulator(method='statevector', device='GPU')
 
    circuit = QuantumCircuit(2, 2)
    circuit.h(0)
    circuit.cx(0, 1)
    circuit.measure([0, 1], [0, 1])
 
    compiled_circuit = transpile(circuit, simulator)
    job = simulator.run(compiled_circuit, shots=shotsAmount)
    result = job.result()
    counts = result.get_counts()
 
    print("Total count for 00 and 11 are:", counts)
    print(circuit)
    return counts
 
result = demo_function(4000)

store the dependencies in a requirements.txt file

requirements.txt
qiskit==1.0.0
qiskit-aer-gpu==0.13.3

Create the container image

Dockerfile
FROM vstirbu/q8s-cuda12
 
COPY requirements.txt /requirements.txt
RUN pip install -r requirements.txt
 
COPY program.py /program.py
 
CMD ["python", "/program.py"]

Build and publish the container

docker build -t registry.example.com/user/program:v1.2.3 .
docker push registry.example.com/user/program:v1.2.3

Create a new job

The job specification needs to explicitly request the needed computational resources. The following example shows how to request one slot on an Nvidia GPU for a quantum computation task.

job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: quantum-job
spec:
  template:
    metadata:
      name: quantum-job
    spec:
      containers:
      - name: quantum-task
        image: registry.example.com/user/program:v1.2.3
        resources:
          limits:
            nvidia.com/gpu: 1
      restartPolicy: Never
      runtimeClassName: nvidia

Run the job

kubectl apply -f job.yaml

Retrieve the results

kubectl logs quantum-job