qat.qpus.ClassicalQPU

class qat.qpus.ClassicalQPU(random=False, **kwargs)

A simulator that only handles classical gates (X, CNOT, CCNOT, etc).

The main purpose of this simulator is to debug classical oracles.

The default behavior is to initialize all the (not so quantum) bits to 0:

from qat.qpus import ClassicalQPU
from qat.lang.AQASM import *

prog = Program()
qbits = prog.qalloc(10)
X(qbits[0])
for i in range(1, 10):
    CNOT(qbits[0], qbits[i])
job = prog.to_circ().to_job()

qpu = ClassicalQPU()
result = qpu.submit(job)
assert len(result.raw_data) == 1 # The result will always have a simple sample
for sample in result:
    print(sample.state)
|1111111111>
This program is trying to run a QPU of class ClassicalQPU that does not implement resource management on a computer where resource management is mandatory.  You should implement estimate_resources_for_batch() in this class, else you will lose the guarantees provided by resource management.

It is also possible to assign a random initial value to the qubits:

from qat.qpus import ClassicalQPU
from qat.lang.AQASM import *

prog = Program()
qbits = prog.qalloc(10)
X(qbits[0])
for i in range(1, 10):
    CNOT(qbits[0], qbits[i])
job = prog.to_circ().to_job()

qpu = ClassicalQPU(random=True)
result = qpus.submit(job)
assert len(result.raw_data) == 1 # The result will always have a simple sample
for sample in result:
    print(sample.state)
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
NameError: name 'qpus' is not defined