Propagate the solver log file name to the solver (#247)

* Propagate the solver log file name to the solver

Previously, the PyPSA network solving functions were not told about
the solver logfile specified in the Snakemake file.

* Pass solver_logfile on as kwargs

The `solve_network` function passes any additional arguments on to the
pypsa `network_lopf` and `ilopf` functions. Now we also pass
`solver_logfile` on as part of kwargs.
This commit is contained in:
Koen van Greevenbroek 2021-05-25 15:55:23 +02:00 committed by GitHub
parent 11af828c39
commit e0215bc5a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -241,7 +241,7 @@ def extra_functionality(n, snapshots):
add_battery_constraints(n)
def solve_network(n, config, solver_log=None, opts='', **kwargs):
def solve_network(n, config, opts='', **kwargs):
solver_options = config['solving']['solver'].copy()
solver_name = solver_options.pop('name')
cf_solving = config['solving']['options']
@ -282,8 +282,9 @@ if __name__ == "__main__":
with memory_logger(filename=fn, interval=30.) as mem:
n = pypsa.Network(snakemake.input[0])
n = prepare_network(n, solve_opts)
n = solve_network(n, config=snakemake.config, solver_dir=tmpdir,
solver_log=snakemake.log.solver, opts=opts)
n = solve_network(n, config=snakemake.config, opts=opts,
solver_dir=tmpdir,
solver_logfile=snakemake.log.solver)
n.export_to_netcdf(snakemake.output[0])
logger.info("Maximum memory usage: {}".format(mem.mem_usage))

View File

@ -111,8 +111,9 @@ if __name__ == "__main__":
fn = getattr(snakemake.log, 'memory', None)
with memory_logger(filename=fn, interval=30.) as mem:
n = prepare_network(n, solve_opts=snakemake.config['solving']['options'])
n = solve_network(n, config, solver_dir=tmpdir,
solver_log=snakemake.log.solver, opts=opts)
n = solve_network(n, config=config, opts=opts,
solver_dir=tmpdir,
solver_logfile=snakemake.log.solver)
n.export_to_netcdf(snakemake.output[0])
logger.info("Maximum memory usage: {}".format(mem.mem_usage))