Skip to content

vv0.3.3

新功能和重要的更新

1.解决了量子云服务调用采样和概率接口时发生的解析错误问题以及全振幅量子虚拟计算异常问题

python
from pyqpanda3.core import H, CNOT, measure, QProg
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)
# service.setup_logging()
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.解决了 VQCircuit 类的 append 方法在添加子电路时的参数映射问题。 示例:

python
import numpy as np
from pyqpanda3.vqcircuit.vqcircuit import VQCircuit
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())

3.修复全振幅量子虚拟机内存占用问题, 例如全振幅模拟器模拟30比特量子电路时,内存占用超过32GB。现在内存占用被优化,确保不会超过理论最大值16GB。

4.VQCResult 类新增 circuits() 接口

新增的 circuits() 方法返回所有生成的电路。对于调试或查看变分量子优化中生成的电路非常有用。 示例:

python
from pyqpanda3.vqcircuit import VQCircuit
from pyqpanda3.core import *
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.解决了Unitary模块内存崩溃

python

import numpy as np
from pyqpanda3.core import *
from pyqpanda3.quantum_info import *
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.解决SIMD模块代码错误导致的QOracle矩阵计算异常

python
import numpy as np
from pyqpanda3.core.core import QProg, random_qcircuit, measure, QCircuit, H, CNOT, Oracle, CPUQVM
import pytest
from pyqpanda3.quantum_info.quantum_info import Unitary

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)

7.优化了originir转QProg接口中CONTROL比特重复等问题

8.已修复在应用噪声模型时,使用双门退相干(dual gate decoherence)在 CPUQVM 上执行量子线路会出现错误的问题。

##补充说明

  1. draw_qprog目前不支持动态线路

Released under the MIT License.