Skip to content

Commit

Permalink
merge validation to main
Browse files Browse the repository at this point in the history
  • Loading branch information
b4pm-devops committed Jan 7, 2025
2 parents 754aaa7 + 882cd0c commit 2d815d4
Show file tree
Hide file tree
Showing 171 changed files with 383 additions and 453 deletions.
6 changes: 4 additions & 2 deletions energy_models/core/energy_study_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
'''
from importlib import import_module

from sostrades_core.study_manager.study_manager import StudyManager
from climateeconomics.core.tools.ClimateEconomicsStudyManager import (
ClimateEconomicsStudyManager,
)
from sostrades_core.tools.bspline.bspline_methods import bspline_method

from energy_models.glossaryenergy import GlossaryEnergy


class EnergyStudyManager(StudyManager):
class EnergyStudyManager(ClimateEconomicsStudyManager):
"""
classdocs
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class IndependentInvestDiscipline(SoSWrapp):
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy_study',
'editable': False,
'structuring': True},
GlossaryEnergy.ForestInvestmentValue: {'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
GlossaryEnergy.ReforestationInvestmentValue: {'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, False),
GlossaryEnergy.ForestInvestmentValue: (
GlossaryEnergy.ReforestationInvestmentValue: (
'float', None, False)},
'namespace': 'ns_invest',
'dataframe_edition_locked': False},
Expand Down Expand Up @@ -226,17 +226,17 @@ def compute_sos_jacobian(self):

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsWoTaxValue, GlossaryEnergy.EnergyInvestmentsWoTaxValue),
(GlossaryEnergy.ForestInvestmentValue, GlossaryEnergy.ForestInvestmentValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
identity * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsMinimizationObjective,),
(GlossaryEnergy.ForestInvestmentValue, GlossaryEnergy.ForestInvestmentValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
ones * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.MaxBudgetConstraintValue, GlossaryEnergy.MaxBudgetConstraintValue),
(GlossaryEnergy.ForestInvestmentValue, GlossaryEnergy.ForestInvestmentValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
identity / max_budget_constraint_ref)

energy_list = inputs_dict[GlossaryEnergy.energy_list]
Expand Down Expand Up @@ -331,18 +331,18 @@ def pimp_string(val: str):

new_chart_energy.series.append(serie)

forest_investment = self.get_sosdisc_inputs(GlossaryEnergy.ForestInvestmentValue)
reforestation_investment = self.get_sosdisc_inputs(GlossaryEnergy.ReforestationInvestmentValue)
chart_name = 'Distribution of reforestation investments'
agriculture_chart = TwoAxesInstanciatedChart(GlossaryEnergy.Years, 'Invest [G$]',
chart_name=chart_name, stacked_bar=True)
serie_agriculture = InstanciatedSeries(
forest_investment[GlossaryEnergy.Years].values.tolist(),
forest_investment[GlossaryEnergy.ForestInvestmentValue].values.tolist(), 'Reforestation', 'bar')
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].values.tolist(), 'Reforestation', 'bar')
agriculture_chart.series.append(serie_agriculture)
instanciated_charts.append(agriculture_chart)
serie = InstanciatedSeries(
forest_investment[GlossaryEnergy.Years].values.tolist(),
forest_investment[GlossaryEnergy.ForestInvestmentValue].tolist(), 'Reforestation', 'bar')
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].tolist(), 'Reforestation', 'bar')

new_chart_energy.series.append(serie)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class InvestmentsRedistributionDisicpline(SoSWrapp):
GlossaryEnergy.YearEnd: GlossaryEnergy.YearEndVar,
GlossaryEnergy.EnergyListName: energy_list_desc_dict,
GlossaryEnergy.CCSListName: ccs_list_desc_dict,
GlossaryEnergy.ForestInvestmentValue: GlossaryEnergy.get_dynamic_variable(GlossaryEnergy.ForestInvestment),
GlossaryEnergy.ReforestationInvestmentValue: GlossaryEnergy.get_dynamic_variable(GlossaryEnergy.ForestInvestment),
GlossaryEnergy.EconomicsDfValue: GlossaryEnergy.get_dynamic_variable(GlossaryEnergy.EconomicsDf),
GlossaryEnergy.EnergyInvestPercentageGDPName: GlossaryEnergy.get_dynamic_variable(
GlossaryEnergy.EnergyInvestPercentageGDP)
Expand Down Expand Up @@ -234,7 +234,7 @@ def compute_sos_jacobian(self):

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsWoTaxValue, GlossaryEnergy.EnergyInvestmentsWoTaxValue),
(GlossaryEnergy.ForestInvestmentValue, GlossaryEnergy.ForestInvestmentValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
identity * 1e-3)

if BiomassDry.name in energy_list:
Expand Down Expand Up @@ -305,18 +305,18 @@ def get_post_processing_list(self, filters=None):

new_chart_energy.series.append(serie)

forest_investment = self.get_sosdisc_inputs(GlossaryEnergy.ForestInvestmentValue)
reforestation_investment = self.get_sosdisc_inputs(GlossaryEnergy.ReforestationInvestmentValue)
chart_name = 'Distribution of reforestation investments '
agriculture_chart = TwoAxesInstanciatedChart(GlossaryEnergy.Years, 'Invest [G$]',
chart_name=chart_name, stacked_bar=True)
serie_agriculture = InstanciatedSeries(
forest_investment[GlossaryEnergy.Years].values.tolist(),
forest_investment[GlossaryEnergy.ForestInvestmentValue].values.tolist(), 'Reforestation', 'bar')
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].values.tolist(), 'Reforestation', 'bar')
agriculture_chart.series.append(serie_agriculture)
instanciated_charts.append(agriculture_chart)
serie = InstanciatedSeries(
forest_investment[GlossaryEnergy.Years].values.tolist(),
forest_investment[GlossaryEnergy.ForestInvestmentValue].tolist(), 'Reforestation', 'bar')
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].tolist(), 'Reforestation', 'bar')

new_chart_energy.series.append(serie)

Expand Down
4 changes: 2 additions & 2 deletions energy_models/core/investments/independent_invest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def compute_energy_investment_wo_tax(self, inputs_dict: dict):
techno_invests = inputs_dict[GlossaryEnergy.invest_mix][self.distribution_list]
techno_invest_sum = techno_invests.sum(axis=1).values

techno_invest_sum += inputs_dict[GlossaryEnergy.ForestInvestmentValue][
GlossaryEnergy.ForestInvestmentValue].values
techno_invest_sum += inputs_dict[GlossaryEnergy.ReforestationInvestmentValue][
GlossaryEnergy.ReforestationInvestmentValue].values
energy_list = inputs_dict[GlossaryEnergy.energy_list]

if BiomassDry.name in energy_list:
Expand Down
8 changes: 4 additions & 4 deletions energy_models/core/investments/investments_redistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
self.techno_list_dict = None
self.total_investments_in_energy = None
self.total_investments_in_energy_w_biomass_dry = None
self.forest_investment_df = None
self.reforestation_investment_df = None
self.inputs_dict = None

def configure_parameters(self, inputs_dict: dict):
Expand All @@ -58,7 +58,7 @@ def configure_parameters(self, inputs_dict: dict):
self.ccs_list = self.inputs_dict[GlossaryEnergy.CCSListName]
self.techno_list_dict = {energy: self.inputs_dict[f'{energy}.{GlossaryEnergy.TechnoListName}'] for energy in
self.energy_list + self.ccs_list if energy != BiomassDry.name}
self.forest_investment_df = self.inputs_dict[GlossaryEnergy.ForestInvestmentValue]
self.reforestation_investment_df = self.inputs_dict[GlossaryEnergy.ReforestationInvestmentValue]

def compute(self):
"""compute investment per technology and total energy investments"""
Expand All @@ -71,8 +71,8 @@ def compute_total_energy_investment_wo_tax(self):
# compute sum of all investments (energy investments + forest investments + biomass_dry investments
# if used in model )
self.total_investments_in_energy_w_biomass_dry = (self.total_investments_in_energy +
self.forest_investment_df[
GlossaryEnergy.ForestInvestmentValue].values)
self.reforestation_investment_df[
GlossaryEnergy.ReforestationInvestmentValue].values)

if BiomassDry.name in self.energy_list:
for techno in ['managed_wood_investment', 'deforestation_investment', 'crop_investment']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ def run(self):

self.store_sos_outputs_values(outputs_dict)

def compute_sos_jacobian(self):
"""Compute nothing, here to avoid l1 error."""
pass

# POST PROCESSING
def get_chart_filter_list(self):

Expand Down
8 changes: 4 additions & 4 deletions energy_models/glossaryenergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
NB_POLES_FULL: int = 8 # number of poles in witness full
NB_POLE_ENERGY_MIX_PROCESS = 12
EXPORT_PROFILES_AT_POLES = "export_invest_profiles_at_poles"
YearEndDefaultValueGradientTest = 2030
YearEndDefaultValueGradientTest = 2050 # TODO: if using 2030 => year
LifetimeDefaultValueGradientTest = 7
YearEndDefault = 2050
YearEndDefaultCore = GlossaryWitnessCore.YearEndDefault
Expand Down Expand Up @@ -134,7 +134,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
TransportCostValue = "transport_cost"
TransportMarginValue = "transport_margin"
TransportDemandValue = "transport_demand"
ForestInvestmentValue = "forest_investment"
ReforestationInvestmentValue = "reforestation_investment"
CarbonCapturedValue = "carbon_captured_type"
InstalledPower = (
"power_production" # todo : rename string to Installed Power [MW] (check unit)
Expand Down Expand Up @@ -482,7 +482,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
}

ForestInvestment = {
"var_name": ForestInvestmentValue,
"var_name": ReforestationInvestmentValue,
"type": "dataframe",
"unit": "G$",
"visibility": "Shared",
Expand All @@ -492,7 +492,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
[1900, GlossaryWitnessCore.YearEndDefault],
False,
),
ForestInvestmentValue: ("float", [0.0, 1e30], False),
ReforestationInvestmentValue: ("float", [0.0, 1e30], False),
},
"namespace": "ns_invest",
"dataframe_edition_locked": False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def setup_usecase(self, study_folder_path=None):
all_streams_demand_ratio.update({energy: 100.0 for energy in self.energy_list})
all_streams_demand_ratio = pd.DataFrame(all_streams_demand_ratio)

forest_invest_df = pd.DataFrame({GlossaryEnergy.Years: self.years, GlossaryEnergy.ForestInvestmentValue: 5})
forest_invest_df = pd.DataFrame({GlossaryEnergy.Years: self.years, GlossaryEnergy.ReforestationInvestmentValue: 5})

co2_land_emissions = pd.DataFrame({
GlossaryEnergy.Years: self.years,
Expand Down Expand Up @@ -605,12 +605,12 @@ def setup_usecase(self, study_folder_path=None):
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.AllStreamsDemandRatioValue}": all_streams_demand_ratio,
f"{self.study_name}.is_stream_demand": True,
f"{self.study_name}.max_mda_iter": 50,
f"{self.study_name}.sub_mda_class": "GSPureNewtonMDA",
f"{self.study_name}.inner_mda_name": "MDAGSNewton",
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.RessourcesCO2EmissionsValue}": resources_CO2_emissions,
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.ResourcesPriceValue}": resources_prices,
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.TargetEnergyProductionValue}": target_energy_prod,
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.MaxBudgetValue}": max_invest,
f"{self.study_name}.{self.coupling_name}.InvestmentDistribution.{GlossaryEnergy.ForestInvestmentValue}": forest_invest_df,
f"{self.study_name}.{self.coupling_name}.InvestmentDistribution.{GlossaryEnergy.ReforestationInvestmentValue}": forest_invest_df,
f"{self.study_name}.{self.coupling_name}.{GlossaryCore.insertGHGAgriLandEmissions.format(GlossaryCore.CO2)}": co2_land_emissions,
f"{self.study_name}.{self.coupling_name}.{GlossaryCore.insertGHGAgriLandEmissions.format(GlossaryCore.CH4)}": co2_land_emissions,
f"{self.study_name}.{self.coupling_name}.{GlossaryCore.insertGHGAgriLandEmissions.format(GlossaryCore.N2O)}": co2_land_emissions,
Expand Down Expand Up @@ -693,7 +693,7 @@ def setup_usecase(self, study_folder_path=None):
f"{self.study_name}.{self.coupling_name}.GHGEmissions.{GlossaryEnergy.SectorListValue}": [],
f"{self.study_name}.{self.coupling_name}.max_mda_iter": 400,
f"{self.study_name}.{self.coupling_name}.tolerance": 1e-10,
f"{self.study_name}.{self.coupling_name}.sub_mda_class": "MDAGaussSeidel",
f"{self.study_name}.{self.coupling_name}.inner_mda_name": "MDAGaussSeidel",
}

dvar_values = self.get_dvar_values(dspace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
get_default_resources_prices,
)
from energy_models.glossaryenergy import GlossaryEnergy
from energy_models.models.carbon_storage.pure_carbon_solid_storage.pure_carbon_solid_storage import (
PureCarbonSS,
)
from energy_models.sos_processes.energy.techno_mix.carbon_capture_mix.usecase import (
DEFAULT_FLUE_GAS_LIST,
)
Expand Down Expand Up @@ -175,14 +172,14 @@ def setup_constraints(self):
list_aggr_type.append(FunctionManager.AGGR_TYPE_SMAX)
list_namespaces.append(GlossaryEnergy.NS_FUNCTIONS)

if GaseousHydrogen.name in self.energy_list:
if "PlasmaCracking" in self.dict_technos[GaseousHydrogen.name]:
list_var.extend([PureCarbonSS.CARBON_TO_BE_STORED_CONSTRAINT])
list_parent.extend(["Carbon_to_be_stored_constraints"])
list_ftype.extend([FunctionManagerDisc.INEQ_CONSTRAINT])
list_weight.extend([0.0])
list_aggr_type.append(FunctionManager.AGGR_TYPE_SMAX)
list_namespaces.append(GlossaryEnergy.NS_FUNCTIONS)
# if GaseousHydrogen.name in self.energy_list:
# if "PlasmaCracking" in self.dict_technos[GaseousHydrogen.name]:
# list_var.extend([PureCarbonSS.CARBON_TO_BE_STORED_CONSTRAINT])
# list_parent.extend(["Carbon_to_be_stored_constraints"])
# list_ftype.extend([FunctionManagerDisc.INEQ_CONSTRAINT])
# list_weight.extend([0.0])
# list_aggr_type.append(FunctionManager.AGGR_TYPE_SMAX)
# list_namespaces.append(GlossaryEnergy.NS_FUNCTIONS)

list_var.extend([EnergyMix.TOTAL_PROD_MINUS_MIN_PROD_CONSTRAINT_DF])
list_parent.extend(["Energy_constraints"])
Expand Down Expand Up @@ -620,7 +617,7 @@ def setup_usecase(self, study_folder_path=None):
f"{self.study_name}.{energy_mix_name}.{GlossaryEnergy.AllStreamsDemandRatioValue}": all_streams_demand_ratio,
f"{self.study_name}.is_stream_demand": True,
f"{self.study_name}.max_mda_iter": 50,
f"{self.study_name}.sub_mda_class": "MDAGaussSeidel",
f"{self.study_name}.inner_mda_name": "MDAGaussSeidel",
f"{self.study_name}.NormalizationReferences.liquid_hydrogen_percentage": np.concatenate(
(np.ones(5) * 1e-4, np.ones(len(self.years) - 5) / 4), axis=None
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup_usecase(self, study_folder_path=None):
f'{self.study_name}.tolerance': 1.0e-7,
f'{self.study_name}.n_processes': 1,
f'{self.study_name}.linearization_mode': 'adjoint',
f'{self.study_name}.sub_mda_class': 'GSPureNewtonMDA',
f'{self.study_name}.inner_mda_name': 'MDAGSNewton',
}
values_dict_list.append(numerical_values_dict)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
limitations under the License.
'''
from sostrades_core.study_manager.study_manager import StudyManager
from climateeconomics.core.tools.ClimateEconomicsStudyManager import (
ClimateEconomicsStudyManager,
)
from sostrades_optimization_plugins.models.func_manager.func_manager_disc import (
FunctionManagerDisc,
)
Expand All @@ -26,7 +28,7 @@
INVEST_DISC_NAME = 'InvestmentDistribution'


class Study(StudyManager):
class Study(ClimateEconomicsStudyManager):
def __init__(
self,
file_path=__file__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def post_processing_filters(execution_engine, namespace):
filters = []
chart_list = []
energy = execution_engine.dm.get_disciplines_with_name(namespace)[
0].mdo_discipline_wrapp.wrapper.energy_name
0].discipline_wrapp.wrapper.energy_name
chart_list += [f'{energy} Capex value']

# The filters are set to False by default since the graphs are not yet
Expand Down Expand Up @@ -144,19 +144,19 @@ def post_processings(execution_engine, namespace, filters):

split_title = namespace.split('.')
title = split_title[len(split_title) - 1] + ' Capex Price'
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].mdo_discipline_wrapp.wrapper.energy_name
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].discipline_wrapp.wrapper.energy_name
if f'{energy} Capex value' in graphs_list:
capex_bar_slider_graph = get_techno_price_data(execution_engine, namespace, title, 'CAPEX_Part', 'Capex')
instanciated_charts.append(capex_bar_slider_graph)

title = split_title[len(split_title) - 1] + ' Opex Price'
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].mdo_discipline_wrapp.wrapper.energy_name
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].discipline_wrapp.wrapper.energy_name
if f'{energy} Capex value' in graphs_list:
opex_bar_slider_graph = get_techno_price_data(execution_engine, namespace, title, 'OPEX_Part', 'Opex')
instanciated_charts.append(opex_bar_slider_graph)

title = split_title[len(split_title) - 1] + ' Total Price'
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].mdo_discipline_wrapp.wrapper.energy_name
energy = execution_engine.dm.get_disciplines_with_name(namespace)[0].discipline_wrapp.wrapper.energy_name
if f'{energy} Capex value' in graphs_list:
total_price_slider_graph = get_techno_price_data(execution_engine, namespace, title, 'Total_Price', 'Price')
instanciated_charts.append(total_price_slider_graph)
Expand Down
Loading

0 comments on commit 2d815d4

Please sign in to comment.