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