Skip to content

Commit a26d3dc

Browse files
FabianHofmannKristijanFaust-OETpre-commit-ci[bot]
authored
Oetc support (refactored) (#487)
* Implement OETC authentication step * Implement cloud provider credentials fetch * Implement OETC model compression and upload * Implement job submission to oetc * Implement waiting for OETC job completion * Implement solution download and decompression * Add proper logging * Add oetc call to linopy model * Add requests dependency * Fix wrong orchestrator endpoint values * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix type hint error caught by mypy * Fix conflicts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add OETC integration entry in the release notes * Ignore false positive type warning * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Extend logging for oetc processes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use remote argument instead of oetc_settings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix mypy errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update solve method docs * fix: missing import of RemoteHandler * refac: use remote dir and move stuff there * feat: increase test coverage * add type hints --------- Co-authored-by: Kristijan Faust <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e2c51d5 commit a26d3dc

File tree

10 files changed

+2671
-17
lines changed

10 files changed

+2671
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ doc/_build
1414
doc/generated
1515
doc/api
1616
.vscode
17+
.idea
1718
Highs.log
1819
paper/
1920
monkeytype.sqlite3
2021
.github/copilot-instructions.md
2122
uv.lock
23+
*.pyc
24+
2225

2326
# Environments
2427
.env

doc/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Version 0.5.6
1010

1111
* Improved variable/expression arithmetic methods so that they correctly handle types
1212
* Gurobi: Pass dictionary as env argument `env={...}` through to gurobi env creation
13+
* Added integration with OETC platform
1314
* Mosek: Remove explicit use of Env, use global env instead
1415
* Objectives can now be created from variables via `linopy.Model.add_objective`.
1516

linopy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from linopy.io import read_netcdf
2121
from linopy.model import Model, Variable, Variables, available_solvers
2222
from linopy.objective import Objective
23-
from linopy.remote import RemoteHandler
23+
from linopy.remote import OetcHandler, RemoteHandler
2424

2525
__all__ = (
2626
"Constraint",
@@ -31,6 +31,7 @@
3131
"LinearExpression",
3232
"Model",
3333
"Objective",
34+
"OetcHandler",
3435
"QuadraticExpression",
3536
"RemoteHandler",
3637
"Variable",

linopy/model.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
)
5959
from linopy.matrices import MatrixAccessor
6060
from linopy.objective import Objective
61+
from linopy.remote import OetcHandler, RemoteHandler
6162
from linopy.solvers import IO_APIS, available_solvers, quadratic_solvers
6263
from linopy.types import (
6364
ConstantLike,
@@ -1050,7 +1051,7 @@ def solve(
10501051
sanitize_zeros: bool = True,
10511052
sanitize_infinities: bool = True,
10521053
slice_size: int = 2_000_000,
1053-
remote: Any = None,
1054+
remote: RemoteHandler | OetcHandler = None, # type: ignore
10541055
progress: bool | None = None,
10551056
**solver_options: Any,
10561057
) -> tuple[str, str]:
@@ -1111,7 +1112,7 @@ def solve(
11111112
Size of the slice to use for writing the lp file. The slice size
11121113
is used to split large variables and constraints into smaller
11131114
chunks to avoid memory issues. The default is 2_000_000.
1114-
remote : linopy.remote.RemoteHandler
1115+
remote : linopy.remote.RemoteHandler | linopy.oetc.OetcHandler, optional
11151116
Remote handler to use for solving model on a server. Note that when
11161117
solving on a rSee
11171118
linopy.remote.RemoteHandler for more details.
@@ -1137,20 +1138,23 @@ def solve(
11371138
f"Keyword argument `io_api` has to be one of {IO_APIS} or None"
11381139
)
11391140

1140-
if remote:
1141-
solved = remote.solve_on_remote(
1142-
self,
1143-
solver_name=solver_name,
1144-
io_api=io_api,
1145-
problem_fn=problem_fn,
1146-
solution_fn=solution_fn,
1147-
log_fn=log_fn,
1148-
basis_fn=basis_fn,
1149-
warmstart_fn=warmstart_fn,
1150-
keep_files=keep_files,
1151-
sanitize_zeros=sanitize_zeros,
1152-
**solver_options,
1153-
)
1141+
if remote is not None:
1142+
if isinstance(remote, OetcHandler):
1143+
solved = remote.solve_on_oetc(self)
1144+
else:
1145+
solved = remote.solve_on_remote(
1146+
self,
1147+
solver_name=solver_name,
1148+
io_api=io_api,
1149+
problem_fn=problem_fn,
1150+
solution_fn=solution_fn,
1151+
log_fn=log_fn,
1152+
basis_fn=basis_fn,
1153+
warmstart_fn=warmstart_fn,
1154+
keep_files=keep_files,
1155+
sanitize_zeros=sanitize_zeros,
1156+
**solver_options,
1157+
)
11541158

11551159
self.objective.set_value(solved.objective.value)
11561160
self.status = solved.status

linopy/remote/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Remote execution handlers for linopy models.
3+
4+
This module provides different handlers for executing optimization models
5+
on remote systems:
6+
7+
- RemoteHandler: SSH-based remote execution using paramiko
8+
- OetcHandler: Cloud-based execution via OET Cloud service
9+
"""
10+
11+
from linopy.remote.oetc import OetcCredentials, OetcHandler, OetcSettings
12+
from linopy.remote.ssh import RemoteHandler
13+
14+
__all__ = [
15+
"RemoteHandler",
16+
"OetcHandler",
17+
"OetcSettings",
18+
"OetcCredentials",
19+
]

0 commit comments

Comments
 (0)