Fake Backend#

Typical Application Scenarios#
Pre-validate whether quantum circuits can be compiled on a specified chip (on specified qubit blocks)
Use limited noise simulation to preliminarily evaluate whether quantum circuits meet expectations
Note FakeBackend’s chip topology and noise model are directly generated based on real quantum computer/chip parameters, and do not support customization. If users want to customize the chip’s topology, please use QPanda3’s Transpiler. If users want to execute circuits using custom noise models, please refer to QPanda3’s Quantum Simulator and Noise Simulation Interface.
A Simple Example#
Using FakeBackend for sampling
Step 1> Login#
# python code
from qpanda3_runtime import RuntimeService
from pyqpanda3.core import *
service = RuntimeService()
service.login('your_valid_api_key')
Step 2> Define the quantum circuit for sampling#
# python code
# Continue from the previous example on this page
prog = QProg()
prog << X(0)<<CNOT(0,1)<<measure(0,0)<<measure(1,1)
Step 3> Select the device to execute the task#
In the example code below, dev is a limited simulation of the real quantum computing chip with id WK_C180, including:
Has the same qubit topology structure
Uses limited noise simulation with noise data (T1, T2, readout errors, etc.) from real quantum chip device specifications
# python code
# Continue from the previous example on this page
dev=service.device('WK_C180').fake_backend() # Here we use the Fake Backend corresponding to the quantum computing chip with id WK_C180
Step 4> Submit the task to Fake Backend#
When the backend device is Fake Backend,
RuntimeService.samplemust run in the__name__ == '__main__'environmentThe sampling calculation of Fake Backend is computed locally on the client
# python code
# Continue from the previous example on this page
task = service.sample(
prog,
dev,
)
Step 5> Query the task execution result#
# python code
# Continue from the previous example on this page
res = task.get_result_sync()
print(f'res:{res}')
Step 6> Run On QPU#
If needed Submit the computing task data verified through Fake Backend to the corresponding real device for execution
# python code
# Continue from the previous example on this page
task2 = task.run_on_real_device(shots=1000)
res2 = task2.get_result_sync()
print(f'res2:',res2)
Complete Example Code#
# python code
from qpanda3_runtime import RuntimeService
from pyqpanda3.core import *
def est():
service = RuntimeService()
service.login('your_valid_api_key')
prog = QProg()
prog << X(0)<<CNOT(0,1)<<measure(0,0)<<measure(1,1)
dev=service.device('WK_C180').fake_backend() # Here we use the Fake Backend corresponding to the quantum computing chip with id WK_C180
task = service.sample(
prog,
dev,
)
res = task.get_result_sync()
print(f'res:{res}')
task2 = task.run_on_real_device(shots=1000)
res2 = task2.get_result_sync()
print(f'res2:',res2)
if __name__ == '__main__':
est()
Compile Only, No Execution#
# python code
from qpanda3_runtime import RuntimeService
from pyqpanda3.core import *
if __name__ == '__main__':
service = RuntimeService()
service.login('your_valid_api_key')
prog = QProg()
prog << CNOT(0, 1) << CNOT(1, 2) << CNOT(2, 3) << measure(0, 0) << measure(1, 1) << measure(2, 2)
fakebackend = service.device('WK_C180').fake_backend()
transpiled_progs, failed_transpiled_circuits = fakebackend.transpile([prog,prog.originir(precision=13)],specified_block=[0,1,18,19])
print('transpiled_progs:\n',transpiled_progs)
print('failed_transpiled_circuits:\n',failed_transpiled_circuits)
Submit Verified Tasks to Real Device#
When using FakeBackend as the computing backend to execute sampling/expectation estimation tasks, the task’s local management object returned by the code can use the interface
QTaskManager.run_on_real_device(shots) to submit the task for execution on the corresponding real quantum computer/chip.
For example code, please refer to Run On QPU