Live LTM - minimal versionΒΆ

This notebook creates a model by using only the Python interface without any input files.

[1]:
import os
from pyltmapi import LtmSession
from pyltm import util, Area, DCLine, Load, AggregatedHydroModule, Inflow, MarketStep
from pathlib import Path

# import logging
# logging.basicConfig(level=logging.DEBUG)

ltm_core_path = os.environ.get(
    "LTM_CORE_PATH", str(Path("~").expanduser().joinpath("ltm/release/bin/"))
)
license_file = os.environ.get(
    "LTM_CORE_LICENSE_FILE", str(Path("~").expanduser().joinpath("ltm/ltm-license.dat"))
)

sim_period = ("2026-W01", "2027-W01")
hist_period = ("1980-01-01T00:00:00Z", "1990-01-01T00:00:00Z")

with LtmSession("live_ltm_minimal", ltm_core_path, overwrite_session=True) as session:
    area1 = Area(name="area1")
    area2 = Area("area2")
    session.model.add(area1)
    session.model.add(area2)

    dcline = DCLine("dcline1")
    dcline.forward_capacity = util.make_constant_txy(200)
    dcline.backward_capacity = util.make_constant_txy(200)
    session.model.add(dcline)

    session.connect(area1, dcline)
    session.connect(dcline, area2)

    load1 = Load("load1")
    load2 = Load("load2")
    load1.capacity = util.make_constant_txy(100)
    load2.capacity = util.make_constant_txy(50)
    session.model.add(load1)
    session.model.add(load2)

    session.connect(load1, area1)
    session.connect(load2, area2)

    constant = Inflow("constant")
    constant.series = util.make_constant_txy(1.0)
    session.model.add(constant)

    aggregated = AggregatedHydroModule("aggregated_hydro")
    aggregated.lower_production_limits = util.make_constant_txy(1.0)
    aggregated.upper_production_limits = util.make_constant_txy(100.0)
    aggregated.lower_reservoir_limits = util.make_constant_txy(0.1)
    aggregated.upper_reservoir_limits = util.make_constant_txy(10000.0)
    aggregated.regulated_power_inflow = util.make_constant_txy(350.0, 10)
    aggregated.unregulated_power_inflow = util.make_constant_txy(50.0, 10)
    aggregated.reservoir_energy = 10000
    aggregated.start_reservoir_energy = 100
    aggregated.station_power = 100
    session.model.add(aggregated)
    session.connect(aggregated, area2)

    ms = MarketStep("market_step")
    ms.price = util.make_constant_txy(260.0)
    ms.capacity = util.make_constant_txy(150.0)
    session.model.add(ms)
    session.connect(ms, area1)

    session.model.global_settings.output_path = "live_minimal_run"
    session.model.global_settings.ltm_license_file_path = license_file

    session.model.global_settings.simulation_period = util.make_txy_period(*sim_period)
    session.model.global_settings.historical_period = util.make_txy_period(*hist_period)
    session.model.global_settings.timesteps_per_week = 56

    last_return_code, program_results = session.run()

    if last_return_code == 0:
        print("Success")
    else:
        print("Failure")

Success