Tamil
மொழிகள்
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

Note

இந்தப் பக்கம் tutorials/operators/02_gradients_framework.ipynb இலிருந்து உருவாக்கப்பட்டது.

Qiskit சாய்வு கட்டமைப்பு

சாய்வு கட்டமைப்பானது குவாண்டம் சாய்வுகளின் மதிப்பீட்டையும் அதன் செயல்பாடுகளையும் செயல்படுத்துகிறது. படிவத்தின் எதிர்பார்ப்பு மதிப்புகளின் நிலையான முதல் வரிசை சாய்வுகளைத் தவிர

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

சாய்வு கட்டமைப்பானது இரண்டாவது வரிசை சாய்வுகளை (ஹெஸ்ஸியன்கள்) மதிப்பீடு செய்வதையும், குவாண்டம் நிலைகளின் குவாண்டம் ஃபிஷர் தகவல் (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…

சாய்வு w.r.t. அளவீட்டு ஆபரேட்டர் அளவுருக்கள்

எதிர்பார்ப்பு மதிப்பின் சாய்வு w.r.t. அளவீட்டு ஆபரேட்டரின் குணகம் முறையே கவனிக்கத்தக்கது \(\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)]

சாய்வு w.r.t. நிலை அளவுருக்கள்

எதிர்பார்ப்பு மதிப்பின் சாய்வு w.r.t. ஒரு நிலை \(|\psi\left(\theta\right)\rangle\) parameter, i.e.

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

மாதிரி நிகழ்தகவுகளின் முறையே w.r.t. ஒரு நிலை \(|\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}.\]

ஒரு சாய்வு w.r.t. ஒரு மாநில அளவுரு வெவ்வேறு முறைகளுடன் மதிப்பீடு செய்யப்படலாம். ஒவ்வொரு முறைக்கும் நன்மைகள் மற்றும் தீமைகள் உள்ளன.

[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\), i.e.,

\[\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)]

யூனிடரீஸ் சாய்வுகளின் நேரியல் சேர்க்கை

Unitaries can be written as \(U\left(\omega\right) = e^{iM\left(\omega\right)}\), where \(M\left(\omega\right)\) denotes a parameterized Hermitian matrix. Further, Hermitian matrices can be decomposed into weighted sums of Pauli terms, i.e., \(M\left(\omega\right) = \sum_pm_p\left(\omega\right)h_p\) with \(m_p\left(\omega\right)\in\mathbb{R}\) and \(h_p=\bigotimes\limits_{j=0}^{n-1}\sigma_{j, p}\) for \(\sigma_{j, p}\in\left\{I, X, Y, Z\right\}\) acting on the \(j^{\text{th}}\) qubit. Thus, the gradients of \(U_k\left(\omega_k\right)\) are given by \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 இன் மூலைவிட்ட கூறுகளின் இரண்டு வகையான இடையூறுகள்.

எந்தவொரு சாய்வு அடிப்படையிலான உகப்பாக்கி மற்றும் / அல்லது 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. எதிர்பார்ப்பு மதிப்பின் க்ராடியென்ட் w.r.t. அளவீட்டு ஆபரேட்டரின் குணகம் முறையே கவனிக்கத்தக்கது \(\hat{O}\left(\omega\right)\), i.e. \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\omega^2}\)

  2. எதிர்பார்ப்பு மதிப்பின் க்ராடியென்ட் w.r.t. ஒரு நிலை \(|\psi\left(\theta\right)\rangle\) parameter, i.e. \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta^2}\)

  3. மாதிரி நிகழ்தகவுகளின் க்ராடியென்ட் w.r.t. ஒரு நிலை \(|\psi\left(\theta\right)\rangle\) parameter, i.e. \(\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. எதிர்பார்ப்பு மதிப்பின் க்ராடியென்ட் w.r.t. ஒரு நிலை \(|\psi\left(\theta\right)\rangle\) அளவுரு மற்றும் அளவீட்டு ஆபரேட்டரின் குணகம் முறையே கவனிக்கத்தக்கது \(\hat{O}\left(\omega\right)\), i.e. \(\frac{\partial^2\langle\psi\left(\theta\right)|\hat{O}\left(\omega\right)|\psi\left(\theta\right)\rangle}{\partial\theta\partial\omega}\)

முதல் இரண்டு ஹெஸியன் வகைகளுக்கு பின்வரும் எடுத்துக்காட்டுகள் கொடுக்கப்பட்டுள்ளன. மீதமுள்ள ஹெஸ்ஸியன்கள் ஒப்பீட்டளவில் மதிப்பீடு செய்யப்படுகிறார்கள்.

ஹெஸ்ஸியன்ஸ் w.r.t. அளவீட்டு ஆபரேட்டர் அளவுருக்கள்

மீண்டும், ஒரு குவாண்டம் நிலையை வரையறுக்கிறோம் \(|\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]]

ஹெஸ்ஸியன்ஸ் w.r.t. நிலை அளவுருக்கள்

[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]]

குவாண்டம் ஃபிஷர் தகவல் (QFI)

குவாண்டம் ஃபிஷர் தகவல் என்பது ஒரு மெட்ரிக் டென்சார், இது ஒரு அளவுரு குவாண்டம் நிலையின் பிரதிநிதித்துவ திறனுக்கான பிரதிநிதியாகும் \(|\psi\left(\theta\right)\rangle = V\left(\theta\right)|\psi\rangle\) உள்ளீட்டு நிலையில் \(|\psi\rangle\), parametrized Ansatz \(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 இன் மூலைவிட்ட தோராயத்தை கூடுதல் வேலை கியூபிட்கள் இல்லாமல் கணக்கிட முடியும். இந்த செயலாக்கத்திற்கு Pauli சுழற்சிகள் மற்றும் அளவீடு செய்யப்படாத கேட்கள் ஆகியவற்றைக் கட்டுப்படுத்த வேண்டும்.

[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.

[ ]: