Objective Module
The objective module provides functions for computing objective functions and their gradients in QSP optimization.
- qsppack.objective.obj_sym(phi, delta, opts)[source]
Compute objective function value for QSP optimization.
- qsppack.objective.grad_sym(phi, delta, opts)[source]
Compute gradient of objective function.
- Parameters:
phi (array_like) – Phase factors for QSP circuit
delta (array_like) – Samples
opts (dict) – Options dictionary containing target function and parameters
- Returns:
grad (ndarray) – Gradient of objective function
obj (ndarray) – Objective function value
- qsppack.objective.grad_sym_real(phi, delta, opts)[source]
Compute gradient using real arithmetic.
Similar to grad_sym but uses only real arithmetic for efficiency.
- Parameters:
phi (array_like) – Phase factors for QSP circuit
delta (array_like) – Samples
opts (dict) – Options dictionary containing target function and parameters
- Returns:
grad (ndarray) – Gradient of objective function
obj (ndarray) – Objective function value
These functions are used internally by the optimization methods to evaluate the quality of phase factor solutions and compute gradients for optimization.
Example usage:
import numpy as np
from qsppack.objective import obj_sym, grad_sym
# Define phase factors and target polynomial
phase_factors = np.array([0.1, 0.2, 0.3])
target_poly = np.array([0, 1])
# Compute objective value
obj_value = obj_sym(phase_factors, target_poly)
# Compute gradient
gradient = grad_sym(phase_factors, target_poly)