Bengali
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

নোট

এই পৃষ্ঠাটি tutorials/operators/02_gradients_framework.ipynb -থেকে বানানো হয়েছে।

Qiskit নতিমাত্রা কাঠামো ( ফ্রেমওয়ার্ক )

নতিমাত্রা কাঠামো ( ফ্রেমওয়ার্ক), কোয়ান্টাম নতিমাত্রাগুলির এবং ফাংশনের মূল্যায়ন এর কার্যকারিতা পরিমাপ করে | নিম্নলিখিত ফর্মের আনুমানিক মানের প্রমান প্রথম ক্রম নতিমাত্রা (গ্রেডিয়েন্ট) ছাড়াও

\[\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle\]

নতিমাত্রা কাঠামোটি (ফ্রেমওয়ার্ক) দ্বিতীয় ক্রমের নতিমাত্রা (হেসিয়ান), এবং কোয়ান্টাম অবস্থার কোয়ান্টাম ফিশার ইনফরমেশন (Quantum Fisher Information, QFI) এর মূল্যায়নও করে \(|\psi\left(\theta\right)\rangle\) |

gradient_framework.png

ইম্পোর্ট বা আনীত করা

[1]:
#General imports
import numpy as np

#Operator Imports
from qiskit.opflow import Z, X, I, StateFn, CircuitStateFn, SummedOp
from qiskit.opflow.gradients import Gradient, NaturalGradient, QFI, Hessian

#Circuit imports
from qiskit.circuit import QuantumCircuit, QuantumRegister, Parameter, ParameterVector, ParameterExpression
from qiskit.circuit.library import EfficientSU2

প্রথম ক্রমের নতিমাত্রা

Given a parameterized quantum state \(|\psi\left(\theta\right)\rangle = V\left(\theta\right)|\psi\rangle\) with input state \(|\psi\rangle\), parametrized Ansatz \(V\left(\theta\right)\), and observable \(\hat{O}\left(\omega\right)=\sum_{i}\omega_i\hat{O}_i\), we want to compute…

পরিমাপ অপারেটর পরামিতি সংক্রান্ত নতিমাত্রা

নতিমাত্রার সম্ভাব্যতার পরিমাণ সম্পর্কে পরিমাপ অপারেটরের একটি সহগ যথাক্রমে পর্যবেক্ষণযোগ্য \(\hat{O}\left(\omega\right)\) , যেমন

\[\frac{\partial\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\omega_i} = \langle\psi\left(\theta\right)|\hat{O}_i\left(\omega\right)|\psi\left(\theta\right)\rangle.\]

সর্বপ্রথমে, আমরা একটি কোয়ান্টাম মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) এবং একটি হ্যামিল্টোনিয়ান \(H\) পর্যবেক্ষণযোগ্য বা দৃষ্টিগ্রাহ্য হিসাবে কাজ করে সংজ্ঞায়িত করি। এরপরে, মান বা অবস্থাটি এবং হ্যামিল্টোনিয়ানটি প্রত্যাশিত মানকে সংজ্ঞায়িত একটি অবজেক্টের মধ্যে আবৃত হয়।

\[\langle\psi\left(\theta\right)|H|\psi\left(\theta\right)\rangle.\]
[2]:
# Instantiate the quantum state
a = Parameter('a')
b = Parameter('b')
q = QuantumRegister(1)
qc = QuantumCircuit(q)
qc.h(q)
qc.rz(a, q[0])
qc.rx(b, q[0])

# Instantiate the Hamiltonian observable
H = (2 * X) + Z

# Combine the Hamiltonian observable and the state
op = ~StateFn(H) @ CircuitStateFn(primitive=qc, coeff=1.)

# Print the operator corresponding to the expectation value
print(op)
ComposedOp([
  OperatorMeasurement(2.0 * X
  + 1.0 * Z),
  CircuitStateFn(
        ┌───┐┌───────┐┌───────┐
  q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b) ├
        └───┘└───────┘└───────┘
  )
])

আমরা পরামিতি গুলির একটি তালিকা গঠন করি যার জন্য আমরা নতিমাত্রাটিকে মূল্যায়ন করতে চাই। এখন, এই তালিকা এবং প্রত্যাশিত মান অপারেটর নতিমাত্রাকে প্রতিনিধিত্বকারী অপারেটর উৎপন্ন করতে ব্যবহৃত হয়।

[3]:
params = [a, b]

# Define the values to be assigned to the parameters
value_dict = {a: np.pi / 4, b: np.pi}

# Convert the operator and the gradient target params into the respective operator
grad = Gradient().convert(operator = op, params = params)

# Print the operator corresponding to the Gradient
print(grad)
ListOp([
  SummedOp([
    ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a + 1.5707963267949) ├┤ RX(b) ├┤ H ├
            └───┘└─────────────────────────┘└───────┘└───┘
      )
    ]),
    -1.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a - 1.5707963267949) ├┤ RX(b) ├┤ H ├
            └───┘└─────────────────────────┘└───────┘└───┘
      )
    ]),
    0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a + 1.5707963267949) ├┤ RX(b) ├
            └───┘└─────────────────────────┘└───────┘
      )
    ]),
    -0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a - 1.5707963267949) ├┤ RX(b) ├
            └───┘└─────────────────────────┘└───────┘
      )
    ])
  ]),
  SummedOp([
    ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.5707963267949) ├┤ H ├
            └───┘└───────┘└─────────────────────────┘└───┘
      )
    ]),
    -1.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.5707963267949) ├┤ H ├
            └───┘└───────┘└─────────────────────────┘└───┘
      )
    ]),
    0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.5707963267949) ├
            └───┘└───────┘└─────────────────────────┘
      )
    ]),
    -0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.5707963267949) ├
            └───┘└───────┘└─────────────────────────┘
      )
    ])
  ])
])

এখন পরামিতিগুলিতে মানগুলি নিয়োগ করতে এবং নতিমাত্রা অপারেটরগুলির মূল্যায়ন করা বাকি।

[4]:
# Assign the parameters and evaluate the gradient
grad_result = grad.assign_parameters(value_dict).eval()
print('Gradient', grad_result)
Gradient [(-1.414213562373094+0j), (-0.7071067811865474+0j)]

মান বা অবস্থা পরামিতি সম্পর্কিত নতিমাত্রা

একটি পরামিতি অবস্থা \(|\psi\left(\theta\right)\rangle\) -এর সম্পর্কিত আনুমানিক মানের নতিমাত্রা, অর্থাৎ

\[\frac{\partial\langle\psi\left(\theta\right)|\hat{O} \left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta}\]

নমুনার সম্ভাবনার যথাক্রমের সম্পর্কে একটি মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) পরামিতি, অর্থাৎ

\[\frac{\partial p_i}{\partial\theta} = \frac{\partial\langle\psi\left(\theta\right)|i\rangle\langle i |\psi\left(\theta\right)\rangle}{\partial\theta}.\]

একটি একটি পরামিতি মান বা অবস্থার সম্পর্কিত নতিমাত্রা বিভিন্ন পদ্ধতি দ্বারা মূল্যায়ন করা যেতে পারে। প্রতিটি পদ্ধতির সুবিধা এবং অসুবিধা আছে।

[5]:
# Define the Hamiltonian with fixed coefficients
H = 0.5 * X - 1 * Z
# Define the parameters w.r.t. we want to compute the gradients
params = [a, b]
# Define the values to be assigned to the parameters
value_dict = { a: np.pi / 4, b: np.pi}

# Combine the Hamiltonian observable and the state into an expectation value operator
op = ~StateFn(H) @ CircuitStateFn(primitive=qc, coeff=1.)
print(op)
ComposedOp([
  OperatorMeasurement(0.5 * X
  - 1.0 * Z),
  CircuitStateFn(
        ┌───┐┌───────┐┌───────┐
  q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b) ├
        └───┘└───────┘└───────┘
  )
])

পরামিতি (প্যারামিটার) স্থানান্তরিত নতিমাত্রা

একটি প্রদত্ত হারমিশিয়ান অপারেটর \(g\) দুটি অনন্য আইগেনভ্যালু \(\pm r\) সহ যা একটি পরামিতিক (প্যারামিটারাইজড) কোয়ান্টাম যুক্তিবর্তনীর (গেইট) জন্য জেনারেটর হিসাবে কাজ করে

\[G(\theta)= e^{-i\theta g}.\]

তারপর, কোয়ান্টাম নতিমাত্রাগুলি আইগেনভ্যালু \(r\) নির্ভর পরামিতিগুলিতে স্থানান্তরিত করে গণনা করা যেতে পারে। সমস্ত প্রামানিক, পরামিতিক (প্যারামিটারাইজড) কিস্কিট (Qiskit) যুক্তিবর্তনীগুলি (গেইট) \(\pi/2\)-এর সাথে স্থানান্তরিত করা যেতে পারে, অর্থাৎ,

\[\frac{\partial\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta} = \left(\langle\psi\left(\theta+\pi/2\right)|\hat{O}\left(\omega\right)|\psi\left(\theta+\pi/2\right)\rangle -\langle\psi\left(\theta-\pi/2\right)|\hat{O}\left(\omega\right)|\psi\left(\theta-\pi/2\right)\rangle\right) / 2।\]

সম্ভাব্যতা নতিমাত্রাগুলি সমপর্যায়ে হিসাব করা হয়।

[6]:
# Convert the expectation value into an operator corresponding to the gradient w.r.t. the state parameters using
# the parameter shift method.
state_grad = Gradient(grad_method='param_shift').convert(operator=op, params=params)
# Print the operator corresponding to the gradient
print(state_grad)
# Assign the parameters and evaluate the gradient
state_grad_result = state_grad.assign_parameters(value_dict).eval()
print('State gradient computed with parameter shift', state_grad_result)
ListOp([
  SummedOp([
    0.25 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a + 1.5707963267949) ├┤ RX(b) ├┤ H ├
            └───┘└─────────────────────────┘└───────┘└───┘
      )
    ]),
    -0.25 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a - 1.5707963267949) ├┤ RX(b) ├┤ H ├
            └───┘└─────────────────────────┘└───────┘└───┘
      )
    ]),
    -0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a + 1.5707963267949) ├┤ RX(b) ├
            └───┘└─────────────────────────┘└───────┘
      )
    ]),
    0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌─────────────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a - 1.5707963267949) ├┤ RX(b) ├
            └───┘└─────────────────────────┘└───────┘
      )
    ])
  ]),
  SummedOp([
    0.25 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.5707963267949) ├┤ H ├
            └───┘└───────┘└─────────────────────────┘└───┘
      )
    ]),
    -0.25 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.5707963267949) ├┤ H ├
            └───┘└───────┘└─────────────────────────┘└───┘
      )
    ]),
    -0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.5707963267949) ├
            └───┘└───────┘└─────────────────────────┘
      )
    ]),
    0.5 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌─────────────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.5707963267949) ├
            └───┘└───────┘└─────────────────────────┘
      )
    ])
  ])
])
State gradient computed with parameter shift [(-0.35355339059327356+0j), (0.7071067811865472+0j)]

একক নতিমাত্রার রৈখিক সমাবেশ

একক (ইউনিটারি ) গুলিকে \(U\left(\omega\right) = e^{iM\left(\omega\right)} ভাবে লেখা যেতে পারে, যেখানে :math:\) কে একটি পরামিতিক (প্যারামিটারাইজড) হারমিশিয়ান ম্যাট্রিক্সকে বোঝায়। উপরন্তু, হারমিশিয়ান ম্যাট্রিক্সগুলিকে পাউলি পদগুলির ওজনযুক্ত সমষ্টিতে বিভক্ত করা যেতে পারে, অর্থাৎ, \(M\left(\omega\right) = \sum_pm_p\left(\omega\right)h_p\) -এর সাথে \(m_p\left(\omega\right)\in\mathbb{R}\) এবং \(h_p=\bigotimes\limits_{j=0}^{n-1}\sigma_{j, p}\) -এর জন্য \(\sigma_{j, p}\in\left\{I, X, Y, Z\right\}\) যা \(j^{\text{th}}\) কিউবিটের উপর কাজ করে। এইভাবে, \(U_k\left(\omega_k\right)\) -এর নতিমাত্রাগুলি দেওয়া হয় \begin{equation*} \frac{\partial U_k\left(\omega_k\right)}{\partial\omega_k} = \sum\limits_pi \frac{\partial m_{k,p}\left(\omega_k\right)}{\partial\omega_k}U_k\left(\omega_k\right)h_{k_p}. \end{equation*}

Simulating physical phenomena by quantum networks -এতে উপস্থিত একটি বর্তনী (সার্কিট) কাঠামোর সাথে এই পর্যবেক্ষণকে একত্রিত করে আমাদের একটি একক কোয়ান্টাম বর্তনীর (সার্কিট) মূল্যায়নে নতিমাত্রা গণনা করতে দেয়।

[7]:
# Convert the expectation value into an operator corresponding to the gradient w.r.t. the state parameter using
# the linear combination of unitaries method.
state_grad = Gradient(grad_method='lin_comb').convert(operator=op, params=params)

# Print the operator corresponding to the gradient
print(state_grad)

# Assign the parameters and evaluate the gradient
state_grad_result = state_grad.assign_parameters(value_dict).eval()
print('State gradient computed with the linear combination method', state_grad_result)
ListOp([
  SummedOp([
    0.5 * ComposedOp([
      OperatorMeasurement(ZZ) * 2.0,
      CircuitStateFn(
             ┌───┐          ┌───────┐┌───────┐┌───┐
       q0_0: ┤ H ├────────■─┤ RZ(a) ├┤ RX(b) ├┤ H ├
             ├───┤┌─────┐ │ └─┬───┬─┘└───────┘└───┘
      q81_0: ┤ H ├┤ SDG ├─■───┤ H ├────────────────
             └───┘└─────┘     └───┘
      ) * 0.7071067811865476
    ]),
    -1.0 * ComposedOp([
      OperatorMeasurement(ZZ) * 2.0,
      CircuitStateFn(
             ┌───┐          ┌───────┐┌───────┐
       q0_0: ┤ H ├────────■─┤ RZ(a) ├┤ RX(b) ├
             ├───┤┌─────┐ │ └─┬───┬─┘└───────┘
      q82_0: ┤ H ├┤ SDG ├─■───┤ H ├───────────
             └───┘└─────┘     └───┘
      ) * 0.7071067811865476
    ])
  ]),
  SummedOp([
    0.5 * ComposedOp([
      OperatorMeasurement(ZZ) * 2.0,
      CircuitStateFn(
             ┌───┐┌───────┐┌───┐┌───────┐┌───┐
       q0_0: ┤ H ├┤ RZ(a) ├┤ X ├┤ RX(b) ├┤ H ├
             ├───┤└┬─────┬┘└─┬─┘└─┬───┬─┘└───┘
      q83_0: ┤ H ├─┤ SDG ├───■────┤ H ├───────
             └───┘ └─────┘        └───┘
      ) * 0.7071067811865476
    ]),
    -1.0 * ComposedOp([
      OperatorMeasurement(ZZ) * 2.0,
      CircuitStateFn(
             ┌───┐┌───────┐┌───┐┌───────┐
       q0_0: ┤ H ├┤ RZ(a) ├┤ X ├┤ RX(b) ├
             ├───┤└┬─────┬┘└─┬─┘└─┬───┬─┘
      q84_0: ┤ H ├─┤ SDG ├───■────┤ H ├──
             └───┘ └─────┘        └───┘
      ) * 0.7071067811865476
    ])
  ])
])
State gradient computed with the linear combination method [(-0.3535533905932737+0j), (0.7071067811865472+0j)]

সসীম পার্থক্য নতিমাত্রা

অন্যান্য পদ্ধতিগুলির মত নয়, সীমিত পার্থক্য নতিমাত্রাগুলি বিশ্লেষণমূলক মানের পরিবর্তে সংখ্যাসূচক অনুমান। এই রূপায়ণটি (ইমপ্লিমেন্টেশন) \(\epsilon \ll 1\) সহ একটি কেন্দ্রীয় পার্থক্য পদ্ধতিকে নিযুক্ত করে

\[\frac{\partial\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta} \approx \frac{1}{2\epsilon} \left(\langle\psi\left(\theta+\epsilon\right)|\hat{O}\left(\omega\right)|\psi\left(\theta+\epsilon\right)\rangle - \partial\langle\psi\left(\theta-\epsilon\right)|\hat{O}\left(\omega\right)|\psi\left(\theta-\epsilon\right)\rangle\right).\]

সম্ভাব্যতা নতিমাত্রাগুলি সমপর্যায়ে হিসাব করা হয়।

[8]:
# Convert the expectation value into an operator corresponding to the gradient w.r.t. the state parameter using
# the finite difference method.
state_grad = Gradient(grad_method='fin_diff').convert(operator=op, params=params)

# Print the operator corresponding to the gradient
print(state_grad)

# Assign the parameters and evaluate the gradient
state_grad_result = state_grad.assign_parameters(value_dict).eval()
print('State gradient computed with finite difference', state_grad_result)
ListOp([
  SummedOp([
    250000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a + 1.0e-6) ├┤ RX(b) ├┤ H ├
            └───┘└────────────────┘└───────┘└───┘
      )
    ]),
    -250000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌────────────────┐┌───────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a - 1.0e-6) ├┤ RX(b) ├┤ H ├
            └───┘└────────────────┘└───────┘└───┘
      )
    ]),
    -500000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a + 1.0e-6) ├┤ RX(b) ├
            └───┘└────────────────┘└───────┘
      )
    ]),
    500000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌────────────────┐┌───────┐
      q0_0: ┤ H ├┤ RZ(a - 1.0e-6) ├┤ RX(b) ├
            └───┘└────────────────┘└───────┘
      )
    ])
  ]),
  SummedOp([
    250000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.0e-6) ├┤ H ├
            └───┘└───────┘└────────────────┘└───┘
      )
    ]),
    -250000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌────────────────┐┌───┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.0e-6) ├┤ H ├
            └───┘└───────┘└────────────────┘└───┘
      )
    ]),
    -500000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b + 1.0e-6) ├
            └───┘└───────┘└────────────────┘
      )
    ]),
    500000.0 * ComposedOp([
      OperatorMeasurement(Z),
      CircuitStateFn(
            ┌───┐┌───────┐┌────────────────┐
      q0_0: ┤ H ├┤ RZ(a) ├┤ RX(b - 1.0e-6) ├
            └───┘└───────┘└────────────────┘
      )
    ])
  ])
])
State gradient computed with finite difference [(-0.35355339057345814+0j), (0.707106781149+0j)]

প্রাকৃতিক নতিমাত্রা

A special type of first order gradient is the natural gradient which has proven itself useful in classical machine learning and is already being studied in the quantum context. This quantity represents a gradient that is 'rescaled' with the inverse Quantum Fisher Information matrix (QFI)

\[QFI ^{-1} \frac{\partial\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta}.\]

কিউএফআই (QFI) উল্টানোর পরিবর্তে, কেউ সমাধান করার জন্য নিয়মিতকরণ সহ অথবা ছাড়া একটি অন্তত বর্গ সমাধানকারীও ব্যবহার করতে পারে

\[QFI x = \frac{\partial\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta}.\]

বাস্তবায়ন (ইমপ্লিমেন্টেশন) L-curve corner search পাশাপাশি কিউএফআই (QFI)-এর কর্ণ (ডায়াগোনাল) উপাদানগুলির দুই ধরনের অস্থিরতা ব্যবহার করে একটি ভালো পরামিতির জন্য স্বয়ংক্রিয় অনুসন্ধানের সাথে রিজ (ridge) এবং ল্যাসো (lasso) নিয়মিতকরণকে সাহায্য করে।

যেকোনো নতিমাত্রা-ভিত্তিক অনুকূলায়ক (অপটিমাইজার) এবং/অথবা ওডিই (ODE) সমাধানকারীর সহ প্রামানিক নতিমাত্রার পরিবর্তে প্রাকৃতিক নতিমাত্রা ব্যবহার করা যেতে পারে।

[9]:
# Besides the method to compute the circuit gradients resp. QFI, a regularization method can be chosen:
# `ridge` or `lasso` with automatic parameter search or `perturb_diag_elements` or `perturb_diag`
# which perturb the diagonal elements of the QFI.
nat_grad = NaturalGradient(grad_method='lin_comb', qfi_method='lin_comb_full', regularization='ridge').convert(
                           operator=op, params=params)

# Assign the parameters and evaluate the gradient
nat_grad_result = nat_grad.assign_parameters(value_dict).eval()
print('Natural gradient computed with linear combination of unitaries', nat_grad_result)
Natural gradient computed with linear combination of unitaries [-2.62895551  1.31447775]

হেসিয়ান (দ্বিতীয় ক্রম নতিমাত্রা)

চার প্রকারের দ্বিতীয় ক্রমের নতিমাত্রাগুলি নতিমাত্রা ফ্রেমওয়ার্ক দ্বারা সমর্থিত।

  1. একটি প্রত্যাশিত মানের নতিমাত্রার সম্পর্কে পরিমাপ অপারেটরের একটি সহগ যথাক্রমে পর্যবেক্ষণযোগ্য \(\hat{O}\left(\omega\right)\), অর্থাৎ \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\omega^2}\)

  2. একটি প্রত্যাশিত মানের নতিমাত্রার সম্পর্কে একটি মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) পরামিতি, অর্থাৎ \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta^2}\)

  3. নমুনা সম্ভাবনাগুলির নতিমাত্রার সম্পর্কে একটি মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) পরামিতি, অর্থাৎ \(\frac{\partial^2 p_i}{\partial\theta^2} = \frac{\partial^2\langle\psi\left(\theta\right)|i\rangle\langle i|\psi\left(\theta\right)\rangle}{\partial\theta^2}\)

  4. একটি প্রত্যাশিত মানের নতিমাত্রার সম্পর্কে একটি মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) পরামিতি এবং পরিমাপ অপারেটরের একটি সহগ যথাক্রমে পর্যবেক্ষণযোগ্য \(\hat{O}\left(\omega\right)\), অর্থাৎ \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta\partial\omega}\)

প্রথম দুটি হেসিয়ান প্রকারের জন্য নিম্নলিখিত উদাহরণগুলি দেওয়া হয়েছে। অবশিষ্ট হেসিয়ানগুলির প্রসঙ্গত মূল্যায়ন করা হয়।

পরিমাপ অপারেটর পরামিতি সম্পর্কিত হেসিয়ান

আবার, আমরা একটি কোয়ান্টাম মান বা অবস্থা \(|\psi\left(\theta\right)\rangle\) সংজ্ঞায়িত করি এবং একটি হ্যামিল্টোনিয়ান \(H\) পর্যবেক্ষণযোগ্য হিসাবে কাজ করে। তারপরে, মান বা অবস্থা এবং হ্যামিল্টোনিয়ান প্রত্যাশার মান নির্ধারণ করে এমন একটি অবজেক্টের মধ্যে আবৃত থাকে

\[\langle\psi\left(\theta\right)|H|\psi\left(\theta\right)\rangle.\]
[10]:
# Instantiate the Hamiltonian observable
H = X

# Instantiate the quantum state with two parameters
a = Parameter('a')
b = Parameter('b')

q = QuantumRegister(1)
qc = QuantumCircuit(q)
qc.h(q)
qc.rz(a, q[0])
qc.rx(b, q[0])

# Combine the Hamiltonian observable and the state
op = ~StateFn(H) @ CircuitStateFn(primitive=qc, coeff=1.)

পরবর্তী, আমরা যে পরামিতিগুলির জন্য আমরা দ্বিতীয় ক্রম নতিমাত্রা গণনা করতে চাই তা চয়ন করতে পারি। - একটি প্রদত্ত টাপল, Hessian দুইটি পরামিতির জন্য দ্বিতীয় ক্রম নতিমাত্রার মূল্যায়ন করবে। - একটি প্রদত্ত তালিকা, Hessian এই পরামিতিগুলির টাপলগুলির সমস্ত সম্ভাব্য সমন্বয়ের জন্য দ্বিতীয় ক্রম নতিমাত্রা মূল্যায়ন করবে।

পরামিতির মানগুলি পরামিতিতে বন্ধনের পরে, হেসিয়ানকে মূল্যায়ন করা যেতে পারে।

[11]:
# Convert the operator and the hessian target coefficients into the respective operator
hessian = Hessian().convert(operator = op, params = [a, b])

# Define the values to be assigned to the parameters
value_dict = {a: np.pi / 4, b: np.pi/4}

# Assign the parameters and evaluate the Hessian w.r.t. the Hamiltonian coefficients
hessian_result = hessian.assign_parameters(value_dict).eval()
print('Hessian \n', np.real(np.array(hessian_result)))
Hessian
 [[-7.07106781e-01  0.00000000e+00]
 [ 0.00000000e+00 -5.55111512e-17]]

অবস্থা (স্টেট) পরামিতি সম্পর্কিত হেসিয়ান

[12]:
# Define parameters
params = [a, b]

# Get the operator object representing the Hessian
state_hess = Hessian(hess_method='param_shift').convert(operator=op, params=params)
# Assign the parameters and evaluate the Hessian
hessian_result = state_hess.assign_parameters(value_dict).eval()
print('Hessian computed using the parameter shift method\n', (np.array(hessian_result)))

# Get the operator object representing the Hessian
state_hess = Hessian(hess_method='lin_comb').convert(operator=op, params=params)
# Assign the parameters and evaluate the Hessian
hessian_result = state_hess.assign_parameters(value_dict).eval()
print('Hessian computed using the linear combination of unitaries method\n', (np.array(hessian_result)))

# Get the operator object representing the Hessian using finite difference
state_hess = Hessian(hess_method='fin_diff').convert(operator=op, params=params)
# Assign the parameters and evaluate the Hessian
hessian_result = state_hess.assign_parameters(value_dict).eval()
print('Hessian computed with finite difference\n', (np.array(hessian_result)))
Hessian computed using the parameter shift method
 [[-7.07106781e-01+0.j  0.00000000e+00+0.j]
 [ 0.00000000e+00+0.j -5.55111512e-17+0.j]]
Hessian computed using the linear combination of unitaries method
 [[-7.07106781e-01+0.j  0.00000000e+00+0.j]
 [ 0.00000000e+00+0.j  5.60000000e-17+0.j]]
Hessian computed with finite difference
 [[-7.07122803e-01+0.j  3.05175781e-05+0.j]
 [ 3.05175781e-05+0.j -6.10351562e-05+0.j]]

কোয়ান্টাম ফিশার ইনফরমেশন (Quantum Fisher Information, QFI)

কোয়ান্টাম ফিশার ইনফরমেশন (Quantum Fisher Information) হল একটি পদ্ধতি (মেট্রিক) টেন্সর যা একটি পরামিতিক (প্যারামিটারাইজড) কোয়ান্টাম মান বা অবস্থা \(|\psi\left(\theta\right)\rangle = V\left(\theta\right)|\psi\rangle\) ইনপুট মান বা অবস্থা \(|\psi\rangle\) সহ, প্যারামেট্রাইজড অন্সাৎজ \(V\left(\theta\right)\) এর প্রতিনিধিত্ব ক্ষমতার প্রতিনিধি।

একটি বিশুদ্ধ মান বা অবস্থার জন্য কিউএফআই (QFI)-এর এন্ট্রিগুলি পড়ে

\[QFI_{kl} = 4 * \text{Re}\left[\langle\partial_k\psi|\partial_l\psi\rangle-\langle\partial_k\psi|\psi\rangle\langle\psi|\partial_l\psi\rangle \right].\]

বর্তনী (সার্কিট) কিউএফআই (QFI) সমূহ

একটি পরামিতিক (প্যারামিটারাইজড) কোয়ান্টাম বর্তনী (সার্কিট) দ্বারা উৎপন্ন একটি কোয়ান্টাম মান বা অবস্থার সাথে সম্পর্কিত কিউএফআই (QFI)-এর মূল্যায়ন বিভিন্ন উপায়ে পরিচালিত হতে পারে।

রৈখিক সমাবেশ পূর্ণ কিউএফআই (QFI)

To compute the full QFI, we use a working qubit as well as intercepting controlled gates. See e.g. Variational ansatz-based quantum simulation of imaginary time evolution.

[13]:
# Wrap the quantum circuit into a CircuitStateFn
state = CircuitStateFn(primitive=qc, coeff=1.)

# Convert the state and the parameters into the operator object that represents the QFI
qfi = QFI(qfi_method='lin_comb_full').convert(operator=state, params=params)
# Define the values for which the QFI is to be computed
values_dict = {a: np.pi / 4, b: 0.1}

# Assign the parameters and evaluate the QFI
qfi_result = qfi.assign_parameters(values_dict).eval()
print('full QFI \n', np.real(np.array(qfi_result)))
full QFI
 [[ 1.0000000e+00 -2.0659798e-16]
 [-2.0659798e-16  5.0000000e-01]]

ব্লক-ডায়াগোনাল এবং ডায়াগোনাল অনুমান

কিউএফআই (QFI)-এর একটি ব্লক-তির্যক (ব্লক-ডায়াগোনাল) সংশ্লিষ্ট তির্যক (ডায়াগোনাল) অনুমান অতিরিক্ত কার্যকরী কিউবিটগুলি ছাড়াই গণনা করা যেতে পারে। এই বাস্তবায়নের জন্য পাউলি ঘূর্ণন এবং অপরামিতিক (আনপ্যারামিটারাইজড) যুক্তিবর্তনীগুলির (গেইট) মধ্যে আনরোলিং প্রয়োজন।

[14]:
# Convert the state and the parameters into the operator object that represents the QFI
# and set the approximation to 'block_diagonal'
qfi = QFI('overlap_block_diag').convert(operator=state, params=params)

# Assign the parameters and evaluate the QFI
qfi_result = qfi.assign_parameters(values_dict).eval()
print('Block-diagonal QFI \n', np.real(np.array(qfi_result)))

# Convert the state and the parameters into the operator object that represents the QFI
# and set the approximation to 'diagonal'
qfi = QFI('overlap_diag').convert(operator=state, params=params)

# Assign the parameters and evaluate the QFI
qfi_result = qfi.assign_parameters(values_dict).eval()
print('Diagonal QFI \n', np.real(np.array(qfi_result)))
Block-diagonal QFI
 [[1.  0. ]
 [0.  0.5]]
Diagonal QFI
 [[1.  0. ]
 [0.  0.5]]

প্রয়োগের (অ্যাপ্লিকেশন) উদাহরণঃ নতিমাত্রা-ভিত্তিক অনুকূলকরণ (অপটিমাইজার) সহ ভি কিউ ই (VQE)

অতিরিক্ত ইম্পোর্ট (আনীত করা)

[15]:
# Execution Imports
from qiskit import Aer
from qiskit.utils import QuantumInstance

# Algorithm Imports
from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import CG

নতিমাত্রা ফ্রেমওয়ার্ক একটি নতিমাত্রা-ভিত্তিক VQE-এর জন্যও ব্যবহার করা যেতে পারে। প্রথমত, হ্যামিল্টোনিয়ান এবং তরঙ্গ ফাংশন অন্সাৎজ আরম্ভ করা হয়।

[16]:
from qiskit.opflow import I, X, Z
from qiskit.circuit import QuantumCircuit, ParameterVector
from scipy.optimize import minimize

# Instantiate the system Hamiltonian
h2_hamiltonian = -1.05 * (I ^ I) + 0.39 * (I ^ Z) - 0.39 * (Z ^ I) - 0.01 * (Z ^ Z) + 0.18 * (X ^ X)

# This is the target energy
h2_energy = -1.85727503

# Define the Ansatz
wavefunction = QuantumCircuit(2)
params = ParameterVector('theta', length=8)
it = iter(params)
wavefunction.ry(next(it), 0)
wavefunction.ry(next(it), 1)
wavefunction.rz(next(it), 0)
wavefunction.rz(next(it), 1)
wavefunction.cx(0, 1)
wavefunction.ry(next(it), 0)
wavefunction.ry(next(it), 1)
wavefunction.rz(next(it), 0)
wavefunction.rz(next(it), 1)

# Define the expectation value corresponding to the energy
op = ~StateFn(h2_hamiltonian) @ StateFn(wavefunction)

এখন, আমরা VQE``টিতে একটি ``Gradient অথবা NaturalGradient ব্যবহার করা উচিত কিনা তা চয়ন করতে পারি, কোয়ান্টাম বর্তনী (সার্কিট) গুলি সম্পাদন করতে একটি QuantumInstance সংজ্ঞায়িত করুন এবং ধারাক্রমটি (অ্যালগরিদম) চালান।

[17]:
grad = Gradient(grad_method='lin_comb')

qi_sv = QuantumInstance(Aer.get_backend('aer_simulator_statevector'),
                        shots=1,
                        seed_simulator=2,
                        seed_transpiler=2)

#Conjugate Gradient algorithm
optimizer = CG(maxiter=50)

# Gradient callable
vqe = VQE(wavefunction, optimizer=optimizer, gradient=grad, quantum_instance=qi_sv)

result = vqe.compute_minimum_eigenvalue(h2_hamiltonian)
print('Result:', result.optimal_value, 'Reference:', h2_energy)
Result: -0.8800000000000001 Reference: -1.85727503
[18]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
QiskitNone
Terra0.17.4
Aer0.8.2
IgnisNone
AquaNone
IBM Q ProviderNone
System information
Python3.8.8 (default, Apr 13 2021, 12:59:45) [Clang 10.0.0 ]
OSDarwin
CPUs2
Memory (Gb)12.0
Fri May 28 09:42:47 2021 EDT

This code is a part of Qiskit

© Copyright IBM 2017, 2021.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.

[ ]: