linopy icon indicating copy to clipboard operation
linopy copied to clipboard

Revise Documentation

Open FabianHofmann opened this issue 3 years ago • 13 comments

Jump has a very good doc, it could serve as a rough orientation https://jump.dev/JuMP.jl/stable/

FabianHofmann avatar Jan 19 '22 09:01 FabianHofmann

Hope to add some more cases, not familiar with xarray and hard to write correct multi-dim models. I think can follow the Google OR-tools guides to add linopy specific examples. I think the guide is very step-by-step. https://developers.google.com/optimization/introduction/overview

loongmxbt avatar Mar 12 '22 11:03 loongmxbt

On https://linopy.readthedocs.io/en/latest/syntax.html objective function is written as multiplication instead of addition

aurelije avatar Jul 08 '22 15:07 aurelije

On https://linopy.readthedocs.io/en/latest/syntax.html objective function is written as multiplication instead of addition

Where are you seeing this? This line

m.add_objective((2 * x).sum() + y.sum())

is a linear expression.

FabianHofmann avatar Jul 11 '22 08:07 FabianHofmann

Where are you seeing this? This line

In mathematical formula (done in Latex I guess). It is on the top of page. In code there is no error

aurelije avatar Jul 11 '22 11:07 aurelije

Exactly, great, thank you!

FabianHofmann avatar Jul 11 '22 11:07 FabianHofmann

Thanks for the excellent library, it is what I was dreaming to have (and have done in similar but not so good way using pandas with multiindex and storing variables in column, doing a lot of manual merging and iterating over coordinates). Could you please add documentation for contributors, how to setup project on your machine, what is the idea of package, technical stuff like how to build, test and so on. I am quite new to python... I have tried to implement classical transport problem (Seattle and San Diego to New York, Chicago and Topeka) and it works perfectly. Maybe that could be included in docs or examples, it is kind of Hello World for Operations research. I would tag this repo also with Operations Research as an applied science on top of Mathematical optimization (Math programming). Adding hype of Data Science would also help, why would we constraint Data Science to Predictive analytics when it should be also prescriptive, the fact that most of DS practitioners do not know prescriptive analysis is their big minus :)

aurelije avatar Jul 13 '22 11:07 aurelije

Regarding approach you have taken, I was contacting Gurobi support asking them to have more data science interface, giving them examples of how I have used pandas to model problem, that they should not be an isolated island in analytics. They also have one example with portfolio optimization that is pandas based and I have used it as a template for model on which I was working. They replied that matrix interface is created for that purpose... I didn't like the answer :)

aurelije avatar Jul 13 '22 11:07 aurelije

Thanks @aurelije, just replying short as I am on vacation. The doc will be improved further, including contributing section and some more background.

The tags are a good idea! Rest of the answer follow later.

FabianHofmann avatar Jul 13 '22 21:07 FabianHofmann

Hi @FabianHofmann I have tried to contribute by adding example but I couldn't setup project. I have checkout project but there is no description on how to set it up beyond pre-commit package. I am also not a full blown Python dev, but more experienced in Java... Anyhow in python everything is more complicated than maven in java world. I have tried with venv, conda and poetry... I have no clue what this setup.py is doing, what pyproject.toml? I can't see any reqiurements.txt or conda-env.yaml... Jupyter is always complaining for not being able to find linopy.version. I can see that there is something in pyproject.toml about that file but have no clue how to generate it. Also setting it up in IntellijIdea caused some problems because of module io which mocks module name from python standard library...

Can you share more insights on how to setup dev environment?

aurelije avatar Oct 07 '22 16:10 aurelije

hey @aurelije so this should work:

  1. fork the repository
  2. git clone [email protected]:aurelije/linopy.git
  3. cd linopy
  4. pip install -e .[dev]
  5. Adjust your code, git add the example and so on
  6. Push to your fork
  7. Make a PR

Sorry, if I repeat basics which might be obvious to you. But most importantly seems to be step 4. Here you install the package from your local repository that is your imported linopy package directly refers to the exact implementation in your folder.

FabianHofmann avatar Oct 18 '22 13:10 FabianHofmann

@FabianHofmann I am trying to add another constraints in my PyPSA model and ended up studying linopy. I have a quick question regarding the documentation since I am looking for the documentation to access the coords (if it could be accessed).

Whenever, we print model, we get a list of the variables and constraints as show below (reduced for simplicity). If I understand it correctly, the variable in parenthesis is the coords as discussed here. I was wondering if there is a way to access those coords variable?

I know in PyPSA I can just use the snapshots to do this but I was wondering if linopy has a build it function for this? I wanted to make a variable based on the existing variables or constraints so I wanted to access the coords.

Linopy LP model
===============

Variables:
----------
 * Generator-p_nom (Generator-ext)
 * Link-p_nom (Link-ext)
 * Link-p (snapshot, Link)


Constraints:
------------
 * Generator-ext-p_nom-lower (Generator-ext)
 * Generator-ext-p_nom-upper (Generator-ext)
 * Link-ext-p-upper (snapshot, Link-ext)

smdumlao avatar Jan 10 '24 09:01 smdumlao

Hey @smdumlao, how about accessing the variable first, and then the corresponding coords?

model.variables['Generator-p_nom'].indexes['Generator-ext']

Hope that is what you are looking for...

FabianHofmann avatar Jan 11 '24 09:01 FabianHofmann

Hi @FabianHofmann, thank you for your response! Yes, this approach worked for me. I can now access the snapshot from the model using

n.model.variables['Generator-p'].indexes['snapshot']

It seems that I should start learning about xarray too :) Checking pypsa.optimizaton was also helpful in understanding the constraints implementation of linopy. I am still unsure how to implement the constraint for curtailment % but this might not be the proper ticket to ask about this.

smdumlao avatar Jan 12 '24 07:01 smdumlao