#error でインストール必要あり
pip install cvxpy

#approximate_error and approximate_noise_model

from qiskit_aer.utils import approximate_quantum_error, approximate_noise_model

import numpy as np

from qiskit_aer.noise import amplitude_damping_error, reset_error, pauli_error
from qiskit.quantum_info import Kraus

#Kraus 演算子
gamma = 0.23
error = amplitude_damping_error(gamma)
results = approximate_quantum_error(error, operator_string="reset")

print(results)

p = ( 1 + gamma -np.sqrt(1 - gamma)) / 2
q = 0

print("")
print("Expected results:")
print("P(0) = {}".format(1 -(p+q)))
print("P(1) = {}".format(p))
print("P(2) = {}".format(q))

#error operatorsはリスト、辞書またはハードコードされたチャネルを示す文字列として与える
gamma = 0.23
k0 = np.array([[1,0],[0,np.sqrt(1-gamma)]])
k1 = np.array([[0, np.sqrt(gamma)], [0,0]])
results =approximate_quantum_error(Kraus([k0, k1]), operator_string="reset")
print(results)

reset_to_0 = Kraus([np.array([[1,0],[0,0]]), np.array([[0,1],[0,0]])])
reset_to_1 = Kraus([np.array([[0,0],[1,0]]), np.array([[0,0],[0,1]])])
reset_kraus = [reset_to_0, reset_to_1]

gamma = 0.23
error = amplitude_damping_error(gamma)
results = approximate_quantum_error(error, operator_list=reset_kraus)
print(results)

import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

