jet20.frontend package

Submodules

jet20.frontend.backends module

jet20.frontend.backends.jet20_default_backend_func(problem, x=None, opt_tolerance=0.001, opt_u=10.0, opt_alpha=0.1, opt_beta=0.5, opt_constraint_tolerance=1e-05, opt_verbose=False, rouding_precision=3, force_rouding=False, device='cuda')[source]

This function is a wrapper of jet20 backend.

Parameters:
  • problem (class:jet20.Problem.) – the problem instance.
  • x (list,numpy.ndarray) – initial solution of the problem
  • opt_u (float) – hyperparameters for interior point method
  • opt_alpha (float) – hyperparameters for line search
  • opt_beta (float) – hyperparameters for line search
  • opt_tolerance (float) – objective value tolerance
  • opt_constraint_tolerance (float) – feasibility tolerance
  • rouding_precision (bool) – rouding precision
  • force_rouding – whether force rounding
Returns:

solution of the problem

Return type:

Solution

jet20.frontend.const module

jet20.frontend.expression module

class jet20.frontend.expression.Constraint(lh: Union[jet20.frontend.expression.Expression, float], rh: Union[jet20.frontend.expression.Expression, float], op: str)[source]

Bases: object

canonicalize() -> (<class 'jet20.frontend.expression.Expression'>, <class 'str'>)[source]
lh
op
rh
with_op(op: str) → jet20.frontend.expression.Constraint[source]
class jet20.frontend.expression.Expression(mat: Optional[numpy.ndarray])[source]

Bases: object

express a mathematical expression or formula in a square matrix form As shown in the following matrix, the [[0. 0. 0. 0. ]

[0. 0. 0. 0.5] [0. 0. 0. 0.5] [0. 0.5 0.5 0. ]]

The Expression overloads +, -, , /, -(neg), *, ==, <, <=, >, >= operators for a convenient way to creating expressions.

const

Returns: The value of const in the expression. As shown in the following matrix, the returned value is the brackets annotation 0. 0. 0. 0. 0. 0. 0. 0.5 => 0. 0. 0. 0. 0.5 0. 0.5 0.5 [0.]

core_mat
dim

Returns: The dim of the core matrix(core matrix must be a square matrix)

equal(other: jet20.frontend.expression.Expression) → bool[source]
expand(n: int) → jet20.frontend.expression.Expression[source]

Get a new Expression which’s core matrix has been expanded to n*n dim. In Mathematically speaking, expand means add variables into expression. Args:

n: expand to n*n dim
Returns:
A new core matrix has been expanded to n*n dim
expand_linear_vector(n: int) → numpy.ndarray[source]
Args:
n: expand to n*1 dim.
Returns:
A new linear parameters vector expanded with zeros(compounded with const)
highest_order

Returns: The highest power of Expression

linear_complete_vector

‘complete’ means the returned linear vector contains const value Returns: A vector for complete parameters of the linear variable and const value As shown in the following matrix, the returned vector is the brackets annotation

0. 0. 0. [0.] 0. 0. 0. [0.5] => [0., 1., 1., 0.] 0. 0. 0. [0.5]

[0. 0.5 0.5] [0.]

shape

Returns: The shape of the core matrix

total_variables

Returns: The total numbers of variables contained in Expression

jet20.frontend.problem module

class jet20.frontend.problem.Problem(name: str = '')[source]

Bases: object

canonical

Return the canonical form of this problem. Returns: (object express matrix, list of constraint tuples).

[[1. 0. 0. 0. ]
[0. 2. 0. 0.5] [[5. 4.0 4.3 0. ] [0. 0. 0. 0.5] [0. 3.2 0. 2.1]
( [0. 0.5 0.5 0. ]], [1. 2. 3. 4. ]], [“<”,”<=”,…], [const1,const2,…])
^ ^ ^ ^ | | | |

object constraits ops consts

constraints(*constraints)[source]

Add a constraint. Args:

constraints: A instance of Constraint, insists of a left value, an operator and a right value.

Returns:

maximize(expr: Union[jet20.frontend.expression.Expression, jet20.frontend.variable.Array])[source]

Add the object math expression of this problem for maximizing it’s value. Args:

expr: A instance of Expression.

Returns:

minimize(expr: Union[jet20.frontend.expression.Expression, jet20.frontend.variable.Array])[source]

Add the object math expression of this problem for minimizing it’s value. Args:

expr: A instance of Expression.

Returns:

reg_solver(name: str, func: Callable)[source]

Register a solver, it will be called to solve the problem later. Args:

name: Name annotation of this solver. func: A function implemented to solve the problem.

Returns:

solve(name: str = 'jet20.backend', *args, **kwargs)[source]

Calling one of the registered solvers to solve the problem., jet20.backend will be used by default.

Parameters:
  • name (str) – One of the registered solvers’s name.
  • args – Extra args depends on the solver
  • kwargs – Extra args depends on the solver
Returns:

solution of the problem depends on the solver

for jet20.backend following args can be used:

Parameters:
  • x (list,numpy.ndarray) – initial solution of the problem
  • opt_u (float) – hyperparameters for interior point method
  • opt_alpha (float) – hyperparameters for line search
  • opt_beta (float) – hyperparameters for line search
  • opt_tolerance (float) – objective value tolerance
  • opt_constraint_tolerance (float) – feasibility tolerance
  • rouding_precision (bool) – rouding precision
  • force_rouding – whether force rounding
Returns:

solution of the problem

Return type:

Solution

variable(name: str, lb: Union[None, float] = None, ub: Union[None, float] = None) → jet20.frontend.variable.Variable[source]

Adding single variable with the name annotation. Args:

name: The name of a variable
Returns:
A new variable
variables(symbols: str, lb: Union[None, List[float], float] = None, ub: Union[None, List[float], float] = None) → List[jet20.frontend.variable.Variable][source]

Adding a batch variables. Example: variables(“x y z”) Args:

symbols: A set of in-order potential variable names, the separator is blank or comma or semicolon[ ,;]
Returns:
Variables, and their name is attached with per symbol
variables_count

Returns: The numbers of variables this problem has contained

jet20.frontend.problem.assert_power(add_expr)[source]

jet20.frontend.variable module

class jet20.frontend.variable.Array(array: List[Union[jet20.frontend.variable.Variable, jet20.frontend.expression.Expression, jet20.frontend.expression.Constraint]] = None)[source]

Bases: object

append(element: Union[jet20.frontend.variable.Variable, jet20.frontend.expression.Expression, jet20.frontend.expression.Constraint])[source]
array
class jet20.frontend.variable.Variable(index: int, name: str, lb: Optional[float] = None, ub: Optional[float] = None, coef: numbers.Real = 1.0)[source]

Bases: jet20.frontend.expression.Expression

index
lb
name
ub
jet20.frontend.variable.quad(q: numpy.ndarray, xs: jet20.frontend.variable.Array) → jet20.frontend.expression.Expression[source]

Module contents

class jet20.frontend.Variable(index: int, name: str, lb: Optional[float] = None, ub: Optional[float] = None, coef: numbers.Real = 1.0)[source]

Bases: jet20.frontend.expression.Expression

index
lb
name
ub
class jet20.frontend.Array(array: List[Union[jet20.frontend.variable.Variable, jet20.frontend.expression.Expression, jet20.frontend.expression.Constraint]] = None)[source]

Bases: object

append(element: Union[jet20.frontend.variable.Variable, jet20.frontend.expression.Expression, jet20.frontend.expression.Constraint])[source]
array
jet20.frontend.quad(q: numpy.ndarray, xs: jet20.frontend.variable.Array) → jet20.frontend.expression.Expression[source]
class jet20.frontend.Expression(mat: Optional[numpy.ndarray])[source]

Bases: object

express a mathematical expression or formula in a square matrix form As shown in the following matrix, the [[0. 0. 0. 0. ]

[0. 0. 0. 0.5] [0. 0. 0. 0.5] [0. 0.5 0.5 0. ]]

The Expression overloads +, -, , /, -(neg), *, ==, <, <=, >, >= operators for a convenient way to creating expressions.

const

Returns: The value of const in the expression. As shown in the following matrix, the returned value is the brackets annotation 0. 0. 0. 0. 0. 0. 0. 0.5 => 0. 0. 0. 0. 0.5 0. 0.5 0.5 [0.]

core_mat
dim

Returns: The dim of the core matrix(core matrix must be a square matrix)

equal(other: jet20.frontend.expression.Expression) → bool[source]
expand(n: int) → jet20.frontend.expression.Expression[source]

Get a new Expression which’s core matrix has been expanded to n*n dim. In Mathematically speaking, expand means add variables into expression. Args:

n: expand to n*n dim
Returns:
A new core matrix has been expanded to n*n dim
expand_linear_vector(n: int) → numpy.ndarray[source]
Args:
n: expand to n*1 dim.
Returns:
A new linear parameters vector expanded with zeros(compounded with const)
highest_order

Returns: The highest power of Expression

linear_complete_vector

‘complete’ means the returned linear vector contains const value Returns: A vector for complete parameters of the linear variable and const value As shown in the following matrix, the returned vector is the brackets annotation

0. 0. 0. [0.] 0. 0. 0. [0.5] => [0., 1., 1., 0.] 0. 0. 0. [0.5]

[0. 0.5 0.5] [0.]

shape

Returns: The shape of the core matrix

total_variables

Returns: The total numbers of variables contained in Expression

class jet20.frontend.Problem(name: str = '')[source]

Bases: object

canonical

Return the canonical form of this problem. Returns: (object express matrix, list of constraint tuples).

[[1. 0. 0. 0. ]
[0. 2. 0. 0.5] [[5. 4.0 4.3 0. ] [0. 0. 0. 0.5] [0. 3.2 0. 2.1]
( [0. 0.5 0.5 0. ]], [1. 2. 3. 4. ]], [“<”,”<=”,…], [const1,const2,…])
^ ^ ^ ^ | | | |

object constraits ops consts

constraints(*constraints)[source]

Add a constraint. Args:

constraints: A instance of Constraint, insists of a left value, an operator and a right value.

Returns:

maximize(expr: Union[jet20.frontend.expression.Expression, jet20.frontend.variable.Array])[source]

Add the object math expression of this problem for maximizing it’s value. Args:

expr: A instance of Expression.

Returns:

minimize(expr: Union[jet20.frontend.expression.Expression, jet20.frontend.variable.Array])[source]

Add the object math expression of this problem for minimizing it’s value. Args:

expr: A instance of Expression.

Returns:

reg_solver(name: str, func: Callable)[source]

Register a solver, it will be called to solve the problem later. Args:

name: Name annotation of this solver. func: A function implemented to solve the problem.

Returns:

solve(name: str = 'jet20.backend', *args, **kwargs)[source]

Calling one of the registered solvers to solve the problem., jet20.backend will be used by default.

Parameters:
  • name (str) – One of the registered solvers’s name.
  • args – Extra args depends on the solver
  • kwargs – Extra args depends on the solver
Returns:

solution of the problem depends on the solver

for jet20.backend following args can be used:

Parameters:
  • x (list,numpy.ndarray) – initial solution of the problem
  • opt_u (float) – hyperparameters for interior point method
  • opt_alpha (float) – hyperparameters for line search
  • opt_beta (float) – hyperparameters for line search
  • opt_tolerance (float) – objective value tolerance
  • opt_constraint_tolerance (float) – feasibility tolerance
  • rouding_precision (bool) – rouding precision
  • force_rouding – whether force rounding
Returns:

solution of the problem

Return type:

Solution

variable(name: str, lb: Union[None, float] = None, ub: Union[None, float] = None) → jet20.frontend.variable.Variable[source]

Adding single variable with the name annotation. Args:

name: The name of a variable
Returns:
A new variable
variables(symbols: str, lb: Union[None, List[float], float] = None, ub: Union[None, List[float], float] = None) → List[jet20.frontend.variable.Variable][source]

Adding a batch variables. Example: variables(“x y z”) Args:

symbols: A set of in-order potential variable names, the separator is blank or comma or semicolon[ ,;]
Returns:
Variables, and their name is attached with per symbol
variables_count

Returns: The numbers of variables this problem has contained