hpc_example

 1import os, sys
 2
 3# path to access c++ files
 4sys.path.append(os.getenv("HOME"))
 5
 6from cunqa import getQPUs
 7from cunqa.circuit import CunqaCircuit
 8
 9
10# --------------------------------------------------
11# Key difference between cloud and HPC
12# example: local = True. By default it is the case.
13# This allows to look for QPUs out of the node where 
14# the work is executing.
15# --------------------------------------------------
16qpus  = getQPUs()
17
18for q in qpus:
19    print(f"QPU {q.id}, backend: {q.backend.name}, simulator: {q.backend.simulator}, version: {q.backend.version}.")
20
21qc = CunqaCircuit(2, 2)
22qc.h(0)
23qc.cx(0, 1)
24qc.measure_all()
25
26qpu = qpus[0]
27qjob = qpu.run(qc, shots = 1000)# non-blocking call
28
29counts = qjob.result.counts
30time = qjob.time_taken
31
32print(f"Result: \n{counts}\n Time taken: {time} s.")