Comments (8)
I cannot reproduce the bug on Linux for both the current master branch of linopy and the latest version v0.0.10
(with xarray v2022.03
).
So you say for both CBC
and cplex
the example works, right? I am a bit confused because the first error appears to be before the solving process and thus should be solver independent.
As for the second error, could you run a debugger and print out the series.index
on the second lowest level? I would be interested how that looks like.
from linopy.
I tried Mac + Python 3.9.5 + xarray 2022.3.0 + linopy 0.0.10
still the same issue. For cbc works fine, for highs comes to an error.
On my windows version Win10 + Python3.8 + xarray 2022.3.0 + linopy 0.0.10
highs solves the problem and also got same Objective value and then get TypeError: Cannot cast Index to dtype int32
. (Different with mac)
Seems highs solves the problem and something went wrong in result reading process. So I think maybe the highs version update causes the problem?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/var/folders/nj/hhq5qdcx2hd8h_5kpp15lscw0000gn/T/ipykernel_53892/3173557130.py in <module>
15
16 m.add_objective(x + 2*y)
---> 17 m.solve('highs')
18
19 m.solution.to_dataframe().plot(grid=True, ylabel='Optimal Value')
~/miniconda3/lib/python3.9/site-packages/linopy/model.py in solve(self, solver_name, io_api, problem_fn, solution_fn, log_fn, basis_fn, warmstart_fn, keep_files, remote, **solver_options)
1042 try:
1043 func = getattr(solvers, f"run_{solver_name}")
-> 1044 res = func(
1045 self,
1046 io_api,
~/miniconda3/lib/python3.9/site-packages/linopy/solvers.py in run_highs(Model, io_api, problem_fn, solution_fn, log_fn, warmstart_fn, basis_fn, keep_files, **solver_options)
369
370 dual = pd.read_fwf(io.BytesIO(dual))["Dual"]
--> 371 dual.index = Model.constraints.ravel("labels", filter_missings=True)
372
373 return dict(
~/miniconda3/lib/python3.9/site-packages/pandas/core/generic.py in __setattr__(self, name, value)
5498 try:
5499 object.__getattribute__(self, name)
-> 5500 return object.__setattr__(self, name, value)
5501 except AttributeError:
5502 pass
~/miniconda3/lib/python3.9/site-packages/pandas/_libs/properties.pyx in pandas._libs.properties.AxisProperty.__set__()
~/miniconda3/lib/python3.9/site-packages/pandas/core/series.py in _set_axis(self, axis, labels, fastpath)
557 if not fastpath:
558 # The ensure_index call above ensures we have an Index object
--> 559 self._mgr.set_axis(axis, labels)
560
561 # ndarray compatibility
~/miniconda3/lib/python3.9/site-packages/pandas/core/internals/managers.py in set_axis(self, axis, new_labels)
214 def set_axis(self, axis: int, new_labels: Index) -> None:
215 # Caller is responsible for ensuring we have an Index object.
--> 216 self._validate_set_axis(axis, new_labels)
217 self.axes[axis] = new_labels
218
~/miniconda3/lib/python3.9/site-packages/pandas/core/internals/base.py in _validate_set_axis(self, axis, new_labels)
55
56 elif new_len != old_len:
---> 57 raise ValueError(
58 f"Length mismatch: Expected axis has {old_len} elements, new "
59 f"values have {new_len} elements"
ValueError: Length mismatch: Expected axis has 22 elements, new values have 20 elements
from linopy.
@loongmxbt FYI, I don't think windows machine are compatible with the latest version and hishs, as we are now using highspy
and this seems to be working on windows yet.
from linopy.
Hi,
I'll revive this thread with some new info. Due to work restrictions I have to use Windows, and due to problem size and financial constraints, I have to use Highs. From some brief contact with the Highs team, there does not seem to be any plans to port highspy
to Windows any time soon. As such, when preparing to solve my models, I go through and make several changes to the master branch code of Linopy (and technically also PyPSA, though those changes are less critical for the actual solving itself).
First, the check for availability of the Highs solver must be changed to look like the check for most of the other solvers (calling a sub, and checking for a response). Then the run_highs-function needs to be changed to use the sub-method again (like in some older version of Linopy), including some changes to the interface since Highs made a breaking change to their output format some time back. Then the solution extraction needs to be different than the master branch.
Going through my list of changes leads to a reliable implementation for using the Highs solver on Windows, so I have code I can share. Not currently doing any compatibility checks related to platform, though, since I know I only need it to work on Windows, and don't need to make sure it still works on Mac and Linux, though, so my code is definitely not "production ready".
We do have a few options, though. One very simple solution is that I just fork Linopy and PyPSA, include my changes, and leave it at that, on a public repo. Another is to make a pull request with several changes, though that would need work by someone else too, since I cannot easily test other environments than Windows.
Any thoughts?
from linopy.
Hey @jonasghini, I am always a bit confused about the status with highspy and windows. In our current CI, we are testing highspy in linopy on windows machines and it seems to working. Have you tried to install linopy like
pip install linopy[solvers]
?
from linopy.
Oh, OK! I'll give that a try!
from linopy.
Yup! Seems to work! This definitely makes my workflow easier! Thanks for the heads up. I'd written it off as a lost cause, but I guess the Highs team snuck in Windows support for highspy when I wasn't looking.
from linopy.
Okay perfect, good to hear. I'll close this issue, feel free to reopen if problems reappear.
from linopy.
Related Issues (20)
- [Feature] Support early stopping for solving such as allowing a relative optimality gap HOT 1
- Add solution values for linear expressions HOT 3
- Enable broadcasting when multiplying with pandas objects HOT 1
- How to add multi-objectives? HOT 6
- Support constant values in objective HOT 1
- Indicate applied masking in string representation of constraints HOT 3
- Change `dims` keyword of sum functions to `dim` HOT 1
- Support for sparse xarrays HOT 23
- show benchmark in readme
- Missing dimension when initializing variable with boundaries of lower dimensions HOT 2
- Improve documentation on overriding coordinates feature HOT 8
- Inconsistent coordinate override in arithmetic expressions HOT 3
- Docstring of `Model.solve()` has wrong return type
- `io_api="mps"` leads to memory overhead
- Error using scip
- Licensed CPLEX not detected HOT 3
- MPS IO changes with highspy >= 1.7
- Re-solving a changed model with "direct" api results in wrong model being solved HOT 1
- add_constraints lhs eats constant HOT 2
- Explore PytOptInferface for writing matrix over native C API HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linopy.