pysolver_view.optimization.constraints module#

Public objective/constraint packing with nonpositive inequalities.

pysolver_view.optimization.constraints.combine_objective_and_constraints(f, c_eq=None, c_ineq=None)[source]#

Combine an objective function with its associated equality and inequality constraints.

This function takes in an objective function value, a set of equality constraints, and a set of inequality constraints. It then returns a combined Numpy array of these values. The constraints can be given as a list, tuple, numpy array, or as individual values.

Parameters:
ffloat

The value of the objective function.

c_eqfloat, list, tuple, np.ndarray, or None

The equality constraint(s). This can be a single value or a collection of values. If None, no equality constraints will be added.

c_ineqfloat, list, tuple, np.ndarray, or None

The inequality constraint(s). This can be a single value or a collection of values. If None, no inequality constraints will be added.

Returns:
np.ndarray

A numpy array consisting of the objective function value followed by equality and inequality constraints.

Examples

>>> combine_objective_and_constraints(1.0, [0.5, 0.6], [0.7, 0.8])
array([1. , 0.5, 0.6, 0.7, 0.8])
>>> combine_objective_and_constraints(1.0, 0.5, 0.7)
array([1. , 0.5, 0.7])
pysolver_view.optimization.constraints.constraint_data_from_values(fitness, equality_count, inequality_count, tol, metadata=None, *, has_metadata=False)[source]#

Validate and annotate detached physical metadata using supplied residuals.

Fitness follows public signs: objective, equalities, then nonpositive inequalities. This helper does no model work and preserves physical names, values, and targets while computing satisfaction from normalized residuals.

pysolver_view.optimization.constraints.count_constraints(var)[source]#

Retrieve the number of constraints based on the provided input.

This function returns the count of constraints based on the nature of the input:

  • None returns 0

  • Scalar values return 1

  • Array-like structures return their length

Parameters:
varNone, scalar, or array-like (list, tuple, np.ndarray)

The input representing the constraint(s). This can be None, a scalar value, or an array-like structure containing multiple constraints.

Returns:
int

The number of constraints:

  • 0 for None

  • 1 for scalar values

  • Length of the array-like for array-like inputs

Examples

>>> count_constraints(None)
0
>>> count_constraints(5.0)
1
>>> count_constraints([1.0, 2.0, 3.0])
3
pysolver_view.optimization.constraints.get_constraint_data(self, x_norm, tol)[source]#

Return constraint evaluation data for the current optimization problem.

This method returns a list of dictionaries describing the satisfaction status of all equality and inequality constraints at a given normalized design point.

If self.problem.constraint_data exists and is valid, it is returned directly after key validation.

Parameters:
x_normarray_like

Normalized design variable vector.

tolfloat

Tolerance for constraint satisfaction.

Returns:
list of dict

Each dictionary contains:

  • name : str Constraint identifier.

  • type : str Either “=” for equality or “<” for inequality constraints.

  • target : float Desired target value (0.0 for all constraints).

  • value : float Actual evaluated constraint value.

  • satisfied : bool Whether the constraint is satisfied (based on tol).

Optionally, each dictionary may also include:

  • normalized_mismatch : float Mismatch scaled by the normalization factor.

  • mismatch : float Raw constraint violation (value - target).

  • normalize : float Normalization factor (if defined).

Raises:
TypeError

If self.problem.constraint_data exists but is not a list of dictionaries, or if required keys are missing from any entry.