38 request: rpc_pb2.SolveRequest,
39) -> optimization_pb2.SolveMathOptModelRequest:
40 """Converts a `SolveRequest` to a `SolveMathOptModelRequest`.
43 request: A `SolveRequest` request built from a MathOpt model.
46 A `SolveMathOptModelRequest` for the Operations Research API.
49 ValueError: If a field that is not supported in the expernal proto is
50 present in the request or if the request can't be parsed to a
51 `SolveMathOptModelRequest`.
53 normalize.math_opt_normalize_proto(request)
54 if request.HasField(
"initializer"):
55 raise ValueError(str(
"initializer is not supported"))
56 for param
in _UNSUPPORTED_SOLVER_SPECIFIC_PARAMETERS:
57 if request.parameters.HasField(param):
58 raise ValueError(f
"SolveParameters.{param} not supported")
61 external_request = optimization_pb2.SolveMathOptModelRequest.FromString(
62 request.SerializeToString()
64 return external_request
65 except (message.DecodeError, message.EncodeError):
66 raise ValueError(
"request can not be parsed")
from None
70 api_response: optimization_pb2.SolveMathOptModelResponse,
71) -> rpc_pb2.SolveResponse:
72 """Converts a `SolveMathOptModelResponse` to a `SolveResponse`.
75 api_response: A `SolveMathOptModelResponse` response built from a MathOpt
79 A `SolveResponse` response built from a MathOpt model.
81 api_response.DiscardUnknownFields()
82 normalize.math_opt_normalize_proto(api_response)
83 response = rpc_pb2.SolveResponse.FromString(api_response.SerializeToString())
84 response.DiscardUnknownFields()