ONNX ModelProto Constraint
- pyscipopt_ml.onnx.add_onnx_constr(scip_model, onnx_model, input_vars, output_vars=None, unique_naming_prefix='', output_type='regression', **kwargs)
Formulate an onnx ModelProto into scip_model.
- Parameters:
scip_model (PySCIPOpt Model) – The SCIP model where the ONNX ModelProto should be inserted.
onnx_model (
onnx.ModelProto) – The onnx model to insert as predictor.input_vars (np.ndarray) – Decision variables used as input for the feed forward neural network in PySCIPOpt Model.
output_vars (np.ndarray) – Decision variables used as output for the feed forward neural network in the PySCIPOpt Model
unique_naming_prefix (str, optional) – A unique naming prefix that is used before all variable and constraint names. This parameter is important if the SCIP model is later printed to file and many predictors are added to the same SCIP model.
output_type ({"classification", "regression"}, default="regression") – If the option chosen is “classification” the output is 1 for exactly one class and 0 for all others. If the option chosen is “regression” then the output for each node of the final layer is the value from the ONNX model.
- Returns:
Object containing information about what was added to model to insert the predictor into it
- Return type:
- Raises:
NoModel – If a section of the ONNX model structure (layer or activation) is not implemented.
Warning
Only MatMul, Gemm, Relu, Sigmoid, Tanh, Softmax, and Softplus operator types are supported. Add, Cast, and Reshape are also often possible, although not in arbitrary contexts.
Note
See
add_predictor_constrfor acceptable values for input_vars and output_vars
- class pyscipopt_ml.onnx.neural_net_onnx.ONNXConstr(scip_model, predictor, input_vars, output_vars=None, unique_naming_prefix='', output_type='regression', **kwargs)
- Transform an ONNX ModelProto that represents a fully connected feed forward neural network
to SCIP constraints with input and output as matrices of variables.
Stores the changes to the SCIP Model for representing an instance into it. Inherits from
AbstractPredictorConstr..- get_error(eps=None)
Returns error in SCIP’s solution with respect to the actual output of the ONNX neural network
- Parameters:
eps (float or int or None, optional) – The maximum allowed tolerance for a mismatch between the actual predictive model and SCIP. If the error is larger than eps an appropriate warning is printed
- Returns:
error – The absolute values of the difference between SCIP’s solution and the trained ML model’s output given the input as defined by SCIP. The matrix is the same dimension as the output of the trained predictor. Using ONNX / pyscipopt, the absolute difference between onnxruntime.InferenceSession(input) and scip.getVal(output).
- Return type:
np.ndarray
- Raises:
NoSolution – If SCIP has no solution (either was not optimized or is infeasible).