ข้ามไปยังเนื้อหาหลัก

Classical Optimizers

Optimizer คืออะไร?

Victoria Lipinska เล่าเกี่ยวกับ classical optimizer และวิธีที่มันทำงานเป็นส่วนหนึ่งของ VQE

คุณจะได้ยินเกี่ยวกับตัวอย่าง optimizer บางตัวและประสิทธิภาพของมันเมื่อมีและไม่มีสัญญาณรบกวน

เอกสารอ้างอิง

บทความต่อไปนี้ถูกอ้างอิงในวิดีโอข้างต้น

เขียนโค้ด classical optimizer

ในบทเรียนก่อนหน้า คุณได้เรียนรู้วิธีสร้าง Hamiltonian ที่เหมาะสำหรับใช้บนคอมพิวเตอร์ควอนตัมและวิธีสร้าง variational circuit คุณยังรู้ด้วยว่า variational circuit (หรือ ansatz) มีพารามิเตอร์ที่ต้องปรับ และพารามิเตอร์ที่ดีที่สุดคือสิ่งที่ให้ค่า cost function หรือพลังงานต่ำสุด ดังนั้นปัญหาของเราลดเหลือการค้นหาใน parameter space เพื่อหาชุดที่ดีที่สุด งานส่วนใหญ่ใน classical optimizers ได้ถูกทำเสร็จแล้วสำหรับเรา เนื่องจาก optimizer ที่ยอดเยี่ยมมีให้ใช้จากหลายแหล่ง

ในบทเรียนนี้ คุณจะได้เรียนรู้:

  • วิธีที่ classical optimizers เข้าร่วมในการคำนวณ VQE
  • classical optimizers ที่มีให้ใช้จาก SciPy มีอะไรบ้าง
  • optimizer ใดที่ ยังไม่มี ใน SciPy และวิธีเสริมโดยใช้ qiskit.algorithms ในระหว่างนี้
  • ตัวเลือกที่มีสำหรับ optimizer เหล่านี้และความสำคัญสำหรับการคำนวณควอนตัม

SciPy คือ Python library โอเพนซอร์สฟรีที่มีแพ็กเกจสำหรับหลายด้านของการคำนวณทางวิทยาศาสตร์ รวมถึงการ optimization โดยเฉพาะ SciPy มีแพ็กเกจ optimization ที่รวม minimize ไว้ด้วย:

from scipy.optimize import minimize This minimize function has several arguments, but the most relevant arguments for quantum chemistry are:

  • The cost function (cost_func). This is related to the Hamiltonian, but also includes some complexities, such as determining the expectation value by using Estimator, and in the case of excited state calculations, might include orthogonality conditions.
  • An initial state (x0) for the system, often the Hartree Fock state
  • Other arguments, including arguments of the cost function itself
  • The method set to the classical optimizer you select
  • Options for the classical optimizer (not to be confused with Session options discussed in the next section)

Some example code is shown below. We restrict our discussion here to the last two arguments.

    cost_func,
x0,
args=(ansatz, hamiltonian, estimator),
method="cobyla",
options={"maxiter": 200})

SciPy has documentation on all the available minimize methods. Here are a few noteworthy examples, all of which are methods for minimizing a scalar function of one or more variables:

  • cobyla: Optimization BY Linear Approximation (COBYLA) algorithm.
  • slsqp: Sequential Least Squares Programming (SLSQP).
  • nelder-mead Nelder-Mead algorithm.

Most available classical optimization algorithms are local minimizers, in that they use various methods to find local minima, but they are not guaranteed to find global minima. Some classical optimizers explicitly estimate gradients and use those to final local minima. Others may use successive linear or quadratic approximations of the objective function to find minima.

These algorithms have several options in common, but with subtle differences. For example, all have the option to specify a maximum number of iterations using the 'maxiter': 200 notation from above. All have some option specifying a different stopping criterion based on function or variable values, though these criteria are slightly different for different algorithms. COBYLA, for example, allows you to specify a tolerance (for example, 'tol': 0.0001) that is the lower bound on a "trust region". In comparison, SLSQP lets you specify a goal in the precision of the function used in the stopping criterion ('ftol'). Nelder-Mead lets you specify a tolerance in the difference between successive parameter (xx) guesses (xatol) or a tolerance in the difference between successive values obtained for the cost function f(x)f(x) (fatol) (or both). For a complete list of available algorithms and options, visit SciPy's minimize documentation.

Source: IBM Quantum docs — updated 15 ม.ค. 2569
English version on doQumentation — updated 7 พ.ค. 2569
This translation based on the English version of approx. 6 พ.ค. 2569