Skip to content

Commit

Permalink
Improve objective-less output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth committed Mar 10, 2023
1 parent 4db06c4 commit d8dd560
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions opvious/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def solve(
outcome = FeasibleOutcome(
reached_at=reached_at,
is_optimal=status == "OPTIMAL",
objective_value=outcome_data["objectiveValue"],
objective_value=outcome_data.get("objectiveValue"),
relative_gap=outcome_data.get("relativeGap"),
)
if not isinstance(outcome, FeasibleOutcome):
Expand Down Expand Up @@ -400,7 +400,8 @@ async def _track_attempt(self, attempt: Attempt, silent=False) -> Any:
print(f"Attempt failed. [{', '.join(details)}]")
else:
adj = "optimal" if ret.is_optimal else "feasible"
details.append(f"objective={ret.objective_value}")
if ret.objective_value is not None:
details.append(f"objective={ret.objective_value}")
if ret.relative_gap is not None:
details.append(
f"gap={format_percent(ret.relative_gap)}"
Expand Down
4 changes: 2 additions & 2 deletions opvious/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def from_graphql(cls, reached_at: datetime, data: Any) -> FailedOutcome:
class FeasibleOutcome:
reached_at: datetime
is_optimal: bool
objective_value: Value
objective_value: Optional[Value]
relative_gap: Optional[Value]

@classmethod
def from_graphql(cls, reached_at: datetime, data: Any) -> FeasibleOutcome:
return FeasibleOutcome(
reached_at=reached_at,
is_optimal=data["isOptimal"],
objective_value=data["objectiveValue"],
objective_value=data.get("objectiveValue"),
relative_gap=data.get("relativeGap"),
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "opvious"
version = "0.7.1"
version = "0.7.2"
description = "Opvious Python SDK"
authors = ["Opvious Engineering <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit d8dd560

Please sign in to comment.