3. Other commonly used utility functions¶
3.1 Bit Topology Mapping¶
The superconducting quantum processor's qubits are not fully connected but are subject to topological connectivity constraints among the qubits. Therefore, programs must adhere to the specified processor's topological structure restrictions when executing.
When users are developing programs and do not wish to consider the chip's topology, they can employ automated qubit mapping programs to establish the correspondence between program qubit numbering and physical qubit numbering.
It's important to note that if the qubit numbering in a user's program is arbitrary (such as attempting fully connected operations), it may not necessarily yield the optimal solution or an effective mapping result in the mapping program. To meet mapping requirements, the mapping process might also involve using SWAP operations for data exchange, which consumes more gate events and, in turn, utilizes a significant portion of qubit lifetime. In some cases, the final mapped circuit might become too long, causing the program to fail to execute or yield results dominated by noise.
Due to the complexity of the mapping algorithms, the mapping process may take some time, so please be patient.
qcis = '''
X Q1
X Q1
Y Q4
Z Q4
H Q4
S Q4
SD Q5
T Q6
TD Q6
X2P Q6
X2M Q6
CZ Q1 Q2
Y2P Q1
Y2M Q1
CZ Q4 Q5
CZ Q3 Q4
CZ Q4 Q8
CZ Q9 Q10
RZ Q2 2.135648
RX Q2 -1.135648
RY Q3 1.8567
RXY Q7 3.2 1.04
CZ Q12 Q14
I Q1 100
B Q6 Q2
M Q7
M Q5
M Q1 Q2
'''
from ezQgd import *
account = Account(login_key='opecT+SO+QFjLXREUU2f8paSJNtTytPPV8Dbbd2T8Zg=', machine_name='gd_qc1')
#For instance, set the user SDK key, and select a quantum computer.
qcis = account.qcis_mapping_isq(qcis)
#Because the mapping results and efficiency vary, we, in collaboration with our partners, offer multiple mapping methods, with the one above being just one of them.
print(qcis)
3.2 Circuit Regular Check (Local)¶
Perform circuit regular checks on the user's client to verify the correctness of gates and parameters, without verifying the correctness of the chip's topology.
When there are variable substitutions in the circuit, please refrain from performing regular checks and circuit optimization.
#When there are variable substitutions, please refrain from performing regular checks and code optimization
qcis_raw=qcis
qcis_circuit=account.qcis_check_regular(qcis_raw)
print(qcis_circuit)
3.3 Circuit Optimization (Local)¶
Perform circuit optimization on the user's client side, attempting to merge neighboring single-qubit gates whenever possible. This feature is currently under development, and we welcome user feedback and community contributions.
Do not perform circuit validation and optimization when the circuit contains replacement variables.
#Optimize the code by combining equivalent operations. Examples of optimizations provided at the current stage are available in the detailed SDK release notes.https://xxxx
qcis_circuit = account.simplify(qcis_raw)
print(qcis_circuit)
3.4 Language Conversion: QCIS to QASM¶
To support more use cases, we offer support for domestic quantum languages, where developers design compilers for their languages to be translated into QCIS for use on the cloud platform.
At the same time, we provide a conversion function to translate QCIS into the international QASM language.
At the moment, this function may not be the most optimal, but it can address our basic requirements.
qcis = '''
X Q1
X Q1
Y Q4
Z Q4
H Q4
S Q4
SD Q5
T Q6
TD Q6
X2P Q6
X2M Q6
CZ Q1 Q2
Y2P Q1
Y2M Q1
CZ Q4 Q5
CZ Q3 Q4
CZ Q4 Q8
CZ Q9 Q10
RZ Q2 2.135648
RX Q2 -1.135648
RY Q3 1.8567
RXY Q7 3.2 1.04
CZ Q12 Q14
I Q1 100
B Q6 Q2
M Q7
M Q5
M Q1 Q2
'''
from ezQgd import *
account = Account(login_key='opecT+SO+QFjLXREUU2f8paSJNtTytPPV8Dbbd2T8Zg=', machine_name='gd_qc1')
#For instance, set the user SDK key, and select a quantum computer.
qasm=account.convert_qcis_to_qasm(qcis)
print(qasm)
3.5 Language Conversion: QASM to QCIS¶
To support a wider range of use cases, we provide support for domestic quantum languages, allowing developers to design compilers for their own languages and convert them to QCIS for use on the cloud platform.
At present, this function may not be the most optimal, but it can address our basic requirements.
qcis=account.convert_qasm_to_qcis(qasm)
print(qcis)
3.6 Other Notes¶
Due to various factors such as high task loads on the cloud platform, abnormal responses from the quantum computer, network timeouts, etc., certain experimental steps may experience anomalies. These anomalies can include job failures, and instances where the job remains in the queue for a prolonged period without progressing to the specified position (non-maintenance state).
Therefore, when designing automated running programs, it's advisable to implement checks on the results of function executions and use try-catch mechanisms to handle exceptions automatically, ensuring that tasks can continue running smoothly over extended periods.