3. The first quantum program submission based on Quingo¶
If you need to submit experiments using other quantum languages on the cloud platform, here's the approach: First, use the chosen programming language to call the language compiler on your local machine, compile the circuit, and output it in QCIS language. Then, submit the experiment according to the QCIS language.
(The cloud platform's JupyterLab environment is preloaded with various language environments, and no additional installation is required. If you have other requirements, please contact customer support.)
3.1 Write Quingo quantum programs¶
Write quantum programs in accordance with Quingo syntax rules.
We will be collaborating with Quingo to make some adjustments to support two-dimensional topology and bit encoding updates.(2023.7.14)
At the current stage, the direct compilation results have issues with bit numbering and topology representation, making it impossible to run the compiled results on existing two-dimensional bit chips.
#This part of the code is inspired by Quingo's sample code.
Quingo_code='''
import std_qcis
operation CNOT(q1: qubit, q2: qubit) : unit {
Y2M(q2);
CZ(q1, q2);
Y2P(q2);
}
operation bell_state() : unit {
using(q0: qubit, q1: qubit) {
H(q0);
CNOT(q0, q1);
measure(q0);
measure(q1);
}
}
'''
f = open("./kernel.qu",'w')
f.write(Quingo_code)
f.close()
3.2 Compile the program and output a QCIS circuit¶
Run host.py to compile the Quingo program.
The Quingo source program is saved by default in the same directory as host.py as kernel.qu.
If you are not in a JupyterLab environment, you can use the following command to compile:
python host.py
from quingo import quingo_interface as qi
qi.set_compiler('mlir')
#Set up the Quingo compiler
if qi.connect_backend('pyqcisim_quantumsim') is False:
exit(-1)
#Connect to the compiler backend
qi.call_quingo("kernel.qu", "bell_state")
#Invoke the compilation service, a successful compilation will return True, and the result will be in the 'build' directory in the current folder as a file named 'circuit_name.qcis'.
#If the compilation is not successful, please adjust the program based on the actual error messages.
#The following is the display of the simulator results
#res = qi.read_result()
#print(res)
#Read and display the simulator results.
connecting pyqcisim_quantumsim... num_qubits: 2
True
After a successful compilation, the QCIS instruction set will be output in the 'build' directory in the same location as the source program, with the name: circuit_name.qcis.
Read the QCIS file output by the Quingo compiler.
f = open("./build/bell_state.qcis",'r')
quingo_qcis=f.read()#Make sure the read length exceeds the total file length.
f.close()
print(quingo_qcis)
H Q1 Y2M Q2 CZ Q1 Q2 Y2P Q2 M Q1 M Q2
3.3 Submit the program to the Quantum Computing Cloud Platform (same as the QCIS process)¶
Submit the compiled QCIS circuit to the Quantum Computing Cloud Platform.
from ezQgd import *
account = Account(login_key='opecT+SO+QFjLXREUU2f8paSJNtTytPPV8Dbbd2T8Zg=', machine_name='gd_qc1')
#Set up your user SDK key, select a quantum computer, create an instance, and once the run is successful, you will receive a message confirming a successful login.
query_id_quingo = account.submit_job(circuit=quingo_qcis, version="Bell_state_quingo")
Wait for the code to complete on the quantum computer and then read, process, and save the experimental results.
if query_id_quingo: result=account.query_experiment(query_id_quingo, max_wait_time=360000) #The maximum wait time is in seconds and is set to 30 seconds by default. Quantum programs can sometimes encounter queues during execution, and the quantum computer itself requires automatic calibration time. If you want to run fully automated programs, it's advisable to set the wait time to be greater than the sum of these. print(result) #Subsequent data applications should be implemented. else : print('When the query_id is empty, it indicates that the experiment submission or execution was unsuccessful, and the experiment needs to be resubmitted')