PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
165 stars 49 forks source link

Allow running job in gurobi environment #160

Closed dannyopts closed 1 year ago

dannyopts commented 1 year ago

I would like to run a gurobi job in an environment that I configure rather than the default environment.

Currently I dont believe there is a way to pass either configuration for the environment or an environment itself.

I have two reasons I want to do this.

  1. I would like to take the COMPUTESERVER parameter from the envornment rather than use a gurobi.lic file.
  2. I would like to run multiple jobs in parallel, but gurobi environments are not thread safe.

For me I would be happy with either a new option grb_create_new_env, I dont really care about reusing envs, or a new option grb_env where I can pass the gurobi env I already created straight down.

Happy to implement this and raise a PR once an approach is agreed.

https://github.com/PyPSA/linopy/blob/8f8682bb50f94bee742aca655aadc38532787c89/linopy/solvers.py#L551C1-L551C1

FabianHofmann commented 1 year ago

hey @dannyopts, this seems to be very much related but not fully solved (as far as I can see) by #162. Perhaps you could build up on this? The easiest approach would be to allow passing an env keyword argument via the solver_options, i.e. using something like this:


def run_gurobi(
    model,
    io_api=None,
    problem_fn=None,
    solution_fn=None,
    log_fn=None,
    warmstart_fn=None,
    basis_fn=None,
    keep_files=False,
    **solver_options,
):
    # ... (existing code)

    with solver_options.get('env') or gurobipy.Env() as env:
        # ... (existing code)

perhaps @tgi-climact has one more thought about this?

tgi-climact commented 1 year ago

@FabianHofmann @dannyopts Sounds good to me !

FabianHofmann commented 1 year ago

solved by #162 (please reopen, if that is not correct)