output=["results/networks/s{simpl}_{clusters}_lv{lv}_{opts}_trace.nc"], log=dict(python="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python_trace.log") ) tmpdir = snakemake.config['solving'].get('tmpdir') if tmpdir is not None: patch_pyomo_tmpdir(tmpdir) logging.basicConfig(filename=snakemake.log.python, level=snakemake.config['logging_level']) n = pypsa.Network(snakemake.input[0]) solver_log = 'solver.log' config = snakemake.config['solving'] opts = snakemake.wildcards.opts.split('-') def save_optimal_capacities(net, iteration, status): net.lines[f"s_nom_opt_{iteration}"] = net.lines["s_nom_opt"] net.links[f"p_nom_opt_{iteration}"] = net.links["p_nom_opt"] setattr(net, f"status_{iteration}", status) setattr(net, f"objective_{iteration}", net.objective) net.iteration = iteration net.export_to_netcdf(snakemake.output[0]) config['options']['max_iterations'] = 12 n = prepare_network(n, config['options']) n = solve_network(n, config, solver_log, opts, save_optimal_capacities) n.export_to_netcdf(snakemake.output[0])
ll='copt', opts='Co2L-24H') configure_logging(snakemake) tmpdir = snakemake.config['solving'].get('tmpdir') if tmpdir is not None: patch_pyomo_tmpdir(tmpdir) n = pypsa.Network(snakemake.input.unprepared) n_optim = pypsa.Network(snakemake.input.optimized) n = set_parameters_from_optimized(n, n_optim) del n_optim opts = [ o for o in snakemake.wildcards.opts.split('-') if not re.match(r'^\d+h$', o, re.IGNORECASE) ] with memory_logger(filename=getattr(snakemake.log, 'memory', None), interval=30.) as mem: n = prepare_network(n, solve_opts=snakemake.config['solving']['options']) n = solve_network(n, config=snakemake.config['solving'], solver_log=snakemake.log.solver, opts=opts) n.export_to_netcdf(snakemake.output[0]) logger.info("Maximum memory usage: {}".format(mem.mem_usage))
if __name__ == "__main__": logging.basicConfig(filename=snakemake.log.python, level=snakemake.config["logging_level"]) opts = [ o for o in snakemake.wildcards.opts.split("-") if not re.match(r"^\d+h$", o, re.IGNORECASE) ] with memory_logger(filename=getattr(snakemake.log, "memory", None), interval=30.0) as mem: n = pypsa.Network(snakemake.input[0]) adjust_network(n) n = prepare_network(n, solve_opts=snakemake.config["solving"]["options"]) n = solve_network( n, config=snakemake.config, solver_log=snakemake.log.solver, opts=opts, ) n.export_to_netcdf(snakemake.output[0]) logger.info("Maximum memory usage: {}".format(mem.mem_usage))