5. Application Demonstration¶
5.1 Principle Demonstration of T1 Measurement¶
The T1 time of a superconducting quantum bit refers to the time during which the quantum state remains in a pure state within the material. It can also be viewed as the coherence time of the qubit. The methods used to measure the T1 time are typically based on the process of decoherence and can be summarized briefly as follows:
Preparing Quantum State: By preparing a specific quantum state, such as the |0⟩ or |1⟩ state, as the initial state to be measured.
Wait Time: After the initial state, allow the quantum state to wait for a period, typically referred to as wait time or repetition measurement cycle, within the superconducting circuit.
Measure Quantum State: After the wait time has elapsed, the information about the quantum state can be obtained by measuring the state of the charge or flux qubit.
Repeat Experiments: By repeating the above process multiple times, the qubit's decoherence behavior can be obtained through multiple measurements of the qubit's state.
Analyze Data: Based on the measurement results, fitting or analyzing the curve of qubit decoherence, one can obtain the T1 time.
In simple terms, T1 measurement requires measuring the relationship between delay times and state changes by performing measurements at different delays after preparing the quantum state to be in the '1' state. The quantum program is very simple but requires multiple circuits with different delays. Here, batch circuits are generated through a classical program.
from ezQgd import *
account = Account(login_key='opecT+SO+QFjLXREUU2f8paSJNtTytPPV8Dbbd2T8Zg=', machine_name='gd_qc1')
import numpy as np
#Configure relevant parameters, corresponding qubits, start and end times for delays, and the step of variation, etc.
qubit0 = 'Q3'
IStart = 0
IEnd = 100000
IStep = 1000
Irange = np.arange(IStart, IEnd, IStep)
#Circuits expressed through classical variables.
template1 = '''
X {qubit0}
I {qubit0} {delay}
M {qubit0}
'''
template = template1
qCircuits = []
#Use quantum circuits with classical program parameters.
for qdelay in Irange:
c = template.format(qubit0 = qubit0, delay = qdelay)
qCircuits.append(c)
#Calculate the number of circuits to be executed, and print one circuit to check if the above substitutions are correct.
print(len(qCircuits))
#Please make sure to confirm the number of circuits; if it exceeds 600, you need to submit them in segments.
print(qCircuits[1])
#Create an experimental directory
create_res = account.create_experiment('T1_demo')
if create_res == 0:
print('Failed to create a new experiment collection')
else :
print('Successfully created a new experiment collection,ID=', create_res)
lab_id = create_res
#The experiment collection ID is recommended to be retained for future use.
import math
import time
# Before submitting, download the experiment parameters used
config_json = account.download_config(down_file=False)
exp_name = "T1_{qubit0}_".format(qubit0 = qubit0)+str(int(time.time()))
query_id = account.submit_job(circuit=qCircuits, version=exp_name, lab_id=lab_id, num_shots=2000, is_verify=False)
#Submit experiments in batches, and be careful not to exceed the allowed number of experiment circuits in a single submission.
# Query experiment results in batches; batch queries return only raw data. The backend supports a maximum of 50 experiment IDs for batch querying.
p1 = []
if query_id:
for idx in range(0, len(query_id), 50):
print(query_id[idx:idx+50])
result=account.query_experiment(query_id[idx:idx+50], max_wait_time=60*1000)
for query_res in result:
# Experiment result transformation, probability conversion, and correction reading
# results = account.readout_data_to_state_probabilities_whole(query_res)
prob = account.probability_calibration(query_res, config_json)
prob = account.probability_correction(prob)
#Requesting the results.
p1.append(prob['1'])
#For T1 measurement, simply plotting the relationship between delay and the probability of the |1> state is sufficient to observe the decay process.
import matplotlib.pyplot as plt
plt.plot(Irange, p1)
plt.xlabel('qubit0 delay')
plt.ylabel('qubit0 |1> probability')
plt.title('T1 test')
plt.show()
#Performing a T1 fit, which involves finding the time it takes for the probability of |1> to drop to 1/e.
#The fitting part in this section is inspired by contributions from users on the cloud platform.
import scipy.optimize as optimize
x=[]
y=p1
e=2.718281828459045
for tt in Irange:
x.append(tt*0.5/1000)
def target_func(x, t1):
return e**(-x/t1)
p0 = 10
para, cov = optimize.curve_fit(target_func, x, y, p0=p0)
print('Fitting parameters are',para, cov)
print('T1 is',para,'us')
plt.figure()
plt.scatter(x, y, color='gray',label="Experiment results")
y_fit = [target_func(a, *para) for a in x]
plt.plot(x, y_fit, color = "blue",label="Fitted curve")
plt.title('y=e^(-x/%.5f)' % (para))
plt.xlabel("t(us)")
plt.ylabel("P(0)")
plt.legend(loc='best')
plt.show()
plt.savefig(f'T1-{qubit0}.png')
5.2 Prime factorization(15)¶
The significance of the Shor's algorithm lies in its breakthrough of traditional cryptographic security, demonstrating the exponential computational speedup capabilities of quantum computers, and driving the development of quantum-safe cryptography and fundamental science.
Below is the code demonstration from the QuantumCTek Cloud Platform's release event for factoring 15 into its prime factors, based on theoretical principles outlined in the paper Nature Physics volume 8, pages719–723 (2012)
# Shor's algorithm factoring 15 = 5 x 3 demonstration
from isq import LocalDevice
from ezQgd import *
import math
import time
account = Account(login_key='opecT+SO+QFjLXREUU2f8paSJNtTytPPV8Dbbd2T8Zg=', machine_name='gd_qc1')
# Quantum program for factoring 15
isq_code = '''
qbit q[66];
procedure main() {
H<q[57]>;
CNOT<q[57],q[51]>;
CNOT<q[57],q[62]>;
H<q[57]>;
M<q[63,57]>;
}
'''
ld = LocalDevice() #compile
ir = ld.compile_to_ir(isq_code, target = "qcis") #Submit quantum circuits to the cloud quantum computer
print(ir)
query_id_isQ = account.submit_job(circuit=ir,num_shots=5000, version="shor_15_v"+str(int(time.time())))
if query_id_isQ:
result=account.query_experiment(query_id_isQ, max_wait_time=360000)
print('========= [Computation completed] =========') # Display results
print('+------------+------------+')
print('| The n-th run | Results |')
print('+------------+------------+')
events = result[0]['results']
index = 0
for s in events[1:100]: #Calculate the greatest common divisor to obtain the final result
index = index + 1
if s[0] == 0 and s[1] == 0:
r = 0
elif s[0] == 1 and s[1] == 0:
r = 1
elif s[0] == 0 and s[1] == 1:
r = 2
elif s[0] == 1 and s[1] == 1:
r = 3
if r == 0:
print('| {:05d}'.format(index)+' | failed |');
else:
p = math.gcd(int(4**(r/2)+1), 15)
q = math.gcd(int(4**(r/2)-1), 15)
print('| {:05d}'.format(index)+' | 15 = '+str(p)+' x '+str(q)+' |')
; CNOT; CNOT; H; M; } ''' ld = LocalDevice() #compile ir = ld.compile_to_ir(isq_code, target = "qcis") #Submit quantum circuits to the cloud quantum computer print(ir) query_id_isQ = account.submit_job(circuit=ir,num_shots=5000, version="shor_15_v"+str(int(time.time()))) if query_id_isQ: result=account.query_experiment(query_id_isQ, max_wait_time=360000) print('========= [Computation completed] =========') # Display results print('+------------+------------+') print('| The n-th run | Results |') print('+------------+------------+') events = result[0]['results'] index = 0 for s in events[1:100]: #Calculate the greatest common divisor to obtain the final result index = index + 1 if s[0] == 0 and s[1] == 0: r = 0 elif s[0] == 1 and s[1] == 0: r = 1 elif s[0] == 0 and s[1] == 1: r = 2 elif s[0] == 1 and s[1] == 1: r = 3 if r == 0: print('| {:05d}'.format(index)+' | failed |'); else: p = math.gcd(int(4**(r/2)+1), 15) q = math.gcd(int(4**(r/2)-1), 15) print('| {:05d}'.format(index)+' | 15 = '+str(p)+' x '+str(q)+' |')