optimizer#

Optimizer: various on-chip optimization algorthims

Classes

Optimizer(target_func, param_init[, ...])

A base class for optimizers.

OptimizerBayesian(target_func, param_init[, ...])

Optimizer based on Bayesian optimization.

OptimizerFourier(target_func, param_init[, ...])

Optimizer based on Fourier series.

OptimizerSPSA(target_func, param_init[, ...])

Optimizer based on SPSA (Simultaneous Perturbation Stochastic Approximation).

class Optimizer(target_func, param_init, random_state=0)[source]#

Bases: object

A base class for optimizers.

Parameters:
  • target_func – The target function to optimize, more specifically, to minimize. It is supposed to accept kwargs in the format of param_init as inputs.

  • param_init – The initial parameters for the target function. The keys of it should be consistent with inputs of target_func.

  • random_state – The random seed for this optimization process.

class OptimizerBayesian(target_func, param_init, random_state=0)[source]#

Bases: Optimizer

Optimizer based on Bayesian optimization.

See bayesian-optimization/BayesianOptimization.

Parameters:
  • target_func – The target function to optimize, more specifically, to minimize. It is supposed to accept kwargs in the format of param_init as inputs.

  • param_init – The initial parameters for the target function. The keys of it should be consistent with inputs of target_func.

  • random_state – The random seed for this optimization process.

Note

In the scenerio of on-chip optimization, the periods of phase shifters are all from 0 to \(2\pi\), so in this program the pbound (a parameter determining the search region in Bayesian-Optimization package) is fixed from 0 to \(2\pi\).

gen_pbounds() dict[source]#
param_register(param_array: ndarray, target: float) None[source]#
param_suggest() ndarray[source]#
run(nstep: int, if_print: bool = False) list[source]#
class OptimizerFourier(target_func, param_init, order=5, lr=0.1, random_state=0)[source]#

Bases: Optimizer

Optimizer based on Fourier series.

Obtain the gradient approximation from the target function approximation.

Parameters:
  • target_func – The target function to optimize, more specifically, to minimize. It is supposed to accept kwargs in the format of param_init as inputs.

  • param_init – The initial parameters for the target function. The keys of it should be consistent with inputs of target_func.

  • order – The order of Fourier series to approximate.

  • lr – The learning rate of the learning process (namely, gradient descent process).

  • random_state – The random seed for this optimization process.

gen_a() ndarray[source]#
param_register(param_array: ndarray, target: ndarray)[source]#
param_suggest() ndarray[source]#
run(nstep: int, if_print: bool = False) list[source]#
class OptimizerSPSA(target_func, param_init, random_state=0)[source]#

Bases: Optimizer

Optimizer based on SPSA (Simultaneous Perturbation Stochastic Approximation).

See https://www.jhuapl.edu/spsa/Pages/MATLAB.htm.

Parameters:
  • target_func – The target function to optimize, more specifically, to minimize. It is supposed to accept kwargs in the format of param_init as inputs.

  • param_init – The initial parameters for the target function. The keys of it should be consistent with inputs of target_func.

  • random_state – The random seed for this optimization process.

ori_random_state() None[source]#
param_register(param_array: ndarray | list, target: ndarray | list) None[source]#
param_suggest() ndarray[source]#
run(nstep: int, if_print: bool = False) list[source]#
set_hyperparam(hyperparam: dict) None[source]#

Set hyperparameters.

The keys include 'a', 'c', 'A', 'nepoch', 'alpha', 'gamma'.