-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract constrained minimizer added
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""This module implements the Minimizer base class.""" | ||
from __future__ import annotations | ||
|
||
import abc | ||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
from bqskit.qis.unitary.unitary import RealVector | ||
|
||
if TYPE_CHECKING: | ||
from bqskit.ir.opt.cost.function import CostFunction | ||
|
||
|
||
class ConstrainedMinimizer(abc.ABC): | ||
""" | ||
The Minimizer class. | ||
An minimizer finds the parameters for a circuit template that minimizes some | ||
CostFunction. | ||
""" | ||
|
||
@abc.abstractmethod | ||
def constrained_minimize( | ||
self, | ||
cost: CostFunction, | ||
cstr: CostFunction, | ||
x0: RealVector, | ||
) -> npt.NDArray[np.float64]: | ||
""" | ||
Minimize `cost` starting from initial point `x0` while obeying `cstr`. | ||
Args: | ||
cost (CostFunction): The CostFunction to minimize. | ||
cstr (CostFunction): The CostFunction used to constrain solutions. | ||
x0 (np.ndarray): The initial point. | ||
Returns: | ||
(np.ndarray): The inputs that best minimizes the cost while obeying | ||
the constraints. | ||
Notes: | ||
This function should be side-effect free. This is because many | ||
calls may be running in parallel. | ||
""" |