我的目标是创建一个噪声模型,其误差与假后端的误差成比例。例如,后端的每个错误强度都是 FakeManila 的 10%。
我从假后端中提取了噪声模型
from qiskit.providers.fake_provider import FakeManila
from qiskit.providers.aer.noise import NoiseModel
manila_backend = FakeManila()
nm_1 = NoiseModel.from_backend(manila_backend)
对于特定的门和特定的量子位(此处为“x”和 2),我可以使用
提取局部量子误差error1 = nm_1._local_quantum_errors['x'][(2,)]
extracted_dict = error1.to_dict()
然后我可以操纵字典中的概率并将更改应用于噪声模型
new_error = error1.from_dict(extracted_dict)
nm_1._local_quantum_errors['x'][(2,)] = new_error
这适用于所有单个量子位以及该特定后端的所有量子位。然而,对于“cx”门,等效过程(甚至不改变任何概率):
error2 = nm_1._local_quantum_errors['cx'][(3, 4)]
extracted_dict = error2.to_dict()
new_error = error2.from_dict(extracted_dict)
nm_1._local_quantum_errors['cx'][(3, 4)] = new_error
产生噪声错误:“指令未识别的错误门”。我怎样才能避免这个问题?
不要尝试直接操作“cx”门的现有错误对象,而是创建具有修改概率的新错误对象,然后将它们添加回噪声模型。
from qiskit.providers.fake_provider import FakeManila
from qiskit.providers.aer.noise import NoiseModel, depolarizing_error
manila_backend = FakeManila()
nm_1 = NoiseModel.from_backend(manila_backend)
scaling_factor = 0.1 # ex, scaling down errors to 10%
for gate in ['x', 'y', 'z', 'h', 's', 't']:
if (gate,) in nm_1._local_quantum_errors:
error = nm_1._local_quantum_errors[gate][(0,)] # lets assume its single qubit gate
new_error = depolarizing_error(error.p * scaling_factor, 1)
nm_1._local_quantum_errors[gate][(0,)] = new_error
if (3, 4) in nm_1._local_quantum_errors['cx']:
cx_error = nm_1._local_quantum_errors['cx'][(3, 4)]
new_cx_error = depolarizing_error(cx_error.p * scaling_factor, 2)
nm_1._local_quantum_errors['cx'][(3, 4)] = new_cx_error
# check nm_1