Skip to content

Commit

Permalink
Abstract constrained minimizer added
Browse files Browse the repository at this point in the history
  • Loading branch information
mtweiden committed Jul 14, 2024
1 parent d1d1c4a commit ac84aa5
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions bqskit/ir/opt/constrained.py
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.
"""

0 comments on commit ac84aa5

Please sign in to comment.