New Features and Important Updates
1.Fixed the parsing error issue and full-amplitude quantum virtual computing exception when calling sampling and probability interfaces in the Quantum Cloud Service.
from pyqpanda3.qcloud import QCloudService, QCloudOptions, QCloudJob, QCloudResult
prog = QProg()
prog << H(0) << CNOT(0, 1) << measure(0, 0) << measure(1, 1)
api_key = '8648ce3d02385fe7d8f921893c90ea408993f977e83377250e1abb/34073'
service = QCloudService(api_key=api_key)
backend = service.backend("full_amplitude")
job = backend.run(prog, 1000)
result = job.result()
probs = result.get_probs()
print("job id : ", job.job_id())
print('probs',probs)
2. Fixed the parameter mapping issue when adding sub-circuits using the append method in the VQCircuit class. Example:
import numpy as np
vqc1 = VQCircuit()
vqc1.set_Param([3, 2])
pa = vqc1.Param([0, 0], 'pa')
pb = vqc1.Param([0, 1], 'pb')
pc = vqc1.Param([1, 0], 'pc')
pd = vqc1.Param([1, 1], 'pd')
pe = vqc1.Param([2, 0], 'pe')
pf = vqc1.Param([2, 1], 'pf')
pg = 3.14 * (pa * pb + pc) * pd
vqc1 << RX(1, pg)
vqc1 << RX(2, pg)
vqc1 << RX(3, pg)
vqc1 << RX(4, pg)
vqc1 << RX(5, pg)
vqc1.display_ansatz()
data1 = np.array([[1, 1], [1.2, 1.3], [2.1, 2.2]])
print(data1)
vqc2 = VQCircuit()
vqc2.set_Param([3])
Pa = vqc2.Param([0], 'Pa')
Pb = vqc2.Param([1], 'Pb')
Pc = vqc2.Param([2], 'Pc')
Pd = Pc * Pb
subvqc = vqc1
vqc2.append(subvqc, [(pa, Pa), (pb, Pb), (pc, Pb), (pd, Pc), (pe, Pb), (pf, Pc)])
print('vqc1:')
ansatz1: str = vqc1.display_ansatz()
print('ansatz1:', ansatz1)
print('vqc2:')
ansatz2: str = vqc2.display_ansatz()
print('ansatz2:', ansatz2)
data = np.random.random(vqc2.mutable_parameter_total())
cir = vqc2(data).at([0])
print('cir', cir)
print('cir ir:\n', cir.originir())
print('pg_val:', pg.get_expression_val())
print('Pd_val:', Pd.get_expression_val())
pg.calculate_expression_val()
Pd.calculate_expression_val()
print('pg_val:', pg.get_expression_val())
print('Pd_val:', Pd.get_expression_val())
Definition vqcircuit.pyi:1
3.Fixed memory usage issue in the full-amplitude quantum virtual machine.
For example, when simulating a 30-qubit quantum circuit, memory usage exceeded 32GB. Now, memory usage is optimized to ensure it does not exceed the theoretical maximum of 16GB.
4.Added circuits() method to the VQCResult class.
The newly added circuits() method returns all generated circuits. This is useful for debugging or viewing the circuits generated during variational quantum optimization.
Example:
vqc = VQCircuit()
vqc.set_Param([2])
vqc << X(0) << CNOT(0, 1) << RZ(1, 3.14) << CRZ(1, 0, 5.14) << RY(0, vqc.Param([0])) << CRY(0, 1, vqc.Param([1]))
params = [
[11.14, 12.14],
[21.14, 22.14]
]
cirs = vqc(params).circuits()
for cir in cirs:
print('type(cir):', type(cir))
for cir in cirs:
print('cir:', cir.originir())
5.Fixed memory crash in the Unitary module.
import numpy as np
from scipy.stats import unitary_group
UA = unitary_group.rvs(8, random_state=1)
cir = QCircuit()
cir << Oracle([0, 1, 2], UA)
cir << H(0)
cir << Oracle([0, 1, 2], UA).dagger()
print(cir)
print(Unitary(cir).ndarray())
6.Fixed QOracle matrix computation exception caused by errors in the SIMD module code.
import numpy as np
from pyqpanda3.core.core import QProg, random_qcircuit, measure, QCircuit, H, CNOT, Oracle, CPUQVM
import pytest
import numpy as np
from scipy.linalg import qr
def random_unitary_matrix(n):
H = np.random.randn(n, n) + 1j * np.random.randn(n, n)
Q, R = qr(H)
Lambda = np.diag(R) / np.abs(np.diag(R))
Q = Q @ np.diag(Lambda)
return Q
U = random_unitary_matrix(8)
prog = QProg()
prog << Oracle([0, 1, 2], U)
prog << Oracle([0, 1, 2], U).dagger()
measure(0, 0)
measure(1, 1)
measure(2, 2)
measure(3, 3)
machine = CPUQVM()
machine.run(prog, 1000)
measure_result = machine.result().get_prob_list()
print(measure_result)
Definition quantum_info.pyi:1
7.Optimized the originir to QProg interface to resolve issues like repeating CONTROL qubits. 8.Fixed the issue when applying noise models, where using dual gate decoherence caused errors when executing circuits on the CPUQVM.
Additional Notes
- The draw_qprog function currently does not support dynamic circuits.