Skip to content

Commit 20207e3

Browse files
Merge branch 'master' into pre-commit-ci-update-config
2 parents ce6476e + 20c9665 commit 20207e3

File tree

11 files changed

+322
-9
lines changed

11 files changed

+322
-9
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ repos:
2424
rev: v0.4.3
2525
hooks:
2626
- id: blackdoc
27+
additional_dependencies: ['black==24.8.0']
2728
- repo: https://github.com/codespell-project/codespell
2829
rev: v2.4.1
2930
hooks:

doc/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Upcoming Version
88
* Reduced memory usage and faster file I/O operations when exporting models to LP format
99
* Improved constraint equality check in `linopy.testing.assert_conequal` to less strict optionally
1010
* Minor bugfix for multiplying variables with numpy type constants
11+
* Harmonize dtypes before concatenation in lp file writing to avoid dtype mismatch errors. This error occurred when creating and storing models in netcdf format using windows machines and loading and solving them on linux machines.
12+
* Add option to use polars series as constant input
13+
* Fix expression merge to explicitly use outer join when combining expressions with disjoint coordinates for consistent behavior across xarray versions
1114

1215
Version 0.5.6
1316
--------------

linopy/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def as_dataarray(
254254
arr = pandas_to_dataarray(arr, coords=coords, dims=dims, **kwargs)
255255
elif isinstance(arr, np.ndarray):
256256
arr = numpy_to_dataarray(arr, coords=coords, dims=dims, **kwargs)
257+
elif isinstance(arr, pl.Series):
258+
arr = numpy_to_dataarray(arr.to_numpy(), coords=coords, dims=dims, **kwargs)
257259
elif isinstance(arr, np.number):
258260
arr = DataArray(float(arr), coords=coords, dims=dims, **kwargs)
259261
elif isinstance(arr, int | float | str | bool | list):
@@ -269,6 +271,7 @@ def as_dataarray(
269271
pd.DataFrame,
270272
np.ndarray,
271273
DataArray,
274+
pl.Series,
272275
]
273276
supported_types_str = ", ".join([t.__name__ for t in supported_types])
274277
raise TypeError(

linopy/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def to_polars(self) -> pl.DataFrame:
631631
short = filter_nulls_polars(short)
632632
check_has_nulls_polars(short, name=f"{self.type} {self.name}")
633633

634-
df = pl.concat([short, long], how="diagonal").sort(["labels", "rhs"])
634+
df = pl.concat([short, long], how="diagonal_relaxed").sort(["labels", "rhs"])
635635
# delete subsequent non-null rhs (happens is all vars per label are -1)
636636
is_non_null = df["rhs"].is_not_null()
637637
prev_non_is_null = is_non_null.shift(1).fill_null(False)

linopy/expressions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
pd.Series,
9999
pd.DataFrame,
100100
np.ndarray,
101+
pl.Series,
101102
)
102103

103104

@@ -1999,6 +2000,8 @@ def merge(
19992000

20002001
if override:
20012002
kwargs["join"] = "override"
2003+
else:
2004+
kwargs.setdefault("join", "outer")
20022005

20032006
if dim == TERM_DIM:
20042007
ds = xr.concat([d[["coeffs", "vars"]] for d in data], dim, **kwargs)

linopy/remote/oetc.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,47 @@ def _submit_job_to_compute_service(self, input_file_name: str) -> str:
268268
except Exception as e:
269269
raise Exception(f"Error submitting job to compute service: {e}")
270270

271+
def _get_job_logs(self, job_uuid: str) -> str:
272+
"""
273+
Fetch logs for a compute job.
274+
275+
Args:
276+
job_uuid: UUID of the job to fetch logs for
277+
278+
Returns:
279+
str: The job logs content as a string
280+
281+
Raises:
282+
Exception: If fetching logs fails
283+
"""
284+
try:
285+
logger.info(f"OETC - Fetching logs for job {job_uuid}...")
286+
287+
response = requests.get(
288+
f"{self.settings.orchestrator_server_url}/compute-job/{job_uuid}/get-logs",
289+
headers={
290+
"Authorization": f"{self.jwt.token_type} {self.jwt.token}",
291+
"Content-Type": "application/json",
292+
},
293+
timeout=30,
294+
)
295+
296+
response.raise_for_status()
297+
logs_data = response.json()
298+
299+
# Extract content from the response structure
300+
logs_content = logs_data.get("content", "")
301+
302+
logger.info(f"OETC - Successfully fetched logs for job {job_uuid}")
303+
return logs_content
304+
305+
except RequestException as e:
306+
logger.warning(f"OETC - Failed to fetch logs for job {job_uuid}: {e}")
307+
return f"[Unable to fetch logs: {e}]"
308+
except Exception as e:
309+
logger.warning(f"OETC - Error fetching logs for job {job_uuid}: {e}")
310+
return f"[Error fetching logs: {e}]"
311+
271312
def wait_and_get_job_data(
272313
self,
273314
job_uuid: str,
@@ -342,7 +383,14 @@ def wait_and_get_job_data(
342383
raise Exception(error_msg)
343384

344385
elif job_result.status == "RUNTIME_ERROR":
345-
error_msg = f"Job failed during execution (status: {job_result.status}). Please check the OETC logs for details."
386+
# Fetch and display logs
387+
logs = self._get_job_logs(job_uuid)
388+
logger.error(f"OETC - Job {job_uuid} logs:\n{logs}")
389+
390+
error_msg = (
391+
f"Job failed during execution (status: {job_result.status}).\n"
392+
f"Logs:\n{logs}"
393+
)
346394
logger.error(f"OETC Error: {error_msg}")
347395
raise Exception(error_msg)
348396

linopy/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING, Union
66

77
import numpy
8-
import numpy.typing
8+
import polars as pl
99
from pandas import DataFrame, Index, Series
1010
from xarray import DataArray
1111
from xarray.core.coordinates import DataArrayCoordinates, DatasetCoordinates
@@ -37,6 +37,7 @@
3737
DataArray,
3838
Series,
3939
DataFrame,
40+
pl.Series,
4041
]
4142
SignLike = Union[str, numpy.ndarray, DataArray, Series, DataFrame] # noqa: UP007
4243
VariableLike = Union["ScalarVariable", "Variable"]

linopy/variables.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,7 @@ def to_pandas(self) -> pd.Series:
287287

288288
def to_linexpr(
289289
self,
290-
coefficient: int
291-
| float
292-
| pd.Series
293-
| pd.DataFrame
294-
| np.ndarray
295-
| DataArray = 1,
290+
coefficient: ConstantLike = 1,
296291
) -> expressions.LinearExpression:
297292
"""
298293
Create a linear expression from the variables.

0 commit comments

Comments
 (0)