Skip to content

Commit

Permalink
Merge branch 'develop' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
simaosr committed Jan 13, 2025
2 parents 0b9f187 + c7d8028 commit 4f3e4ed
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
repos:
- repo: https://github.com/b4pm-devops/sostrades-pre-commit.git
rev: v1.1.2
hooks:
- id: update-headers
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
args: [
--fix,
--preview,
--exit-non-zero-on-fix,
--config=ruff.toml,
]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: LICENSES/headers
- id: check-yaml
# !reference is specific to gitlab
# !! prefix is specific to mkdocs
exclude: \.gitlab-ci.yml|mkdocs.yml
- id: check-added-large-files
- id: check-json
- id: pretty-format-json
args: [
--autofix,
--no-sort-keys,
]
exclude: \.ipynb
- id: check-toml
- id: destroyed-symlinks
- id: check-symlinks
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
hooks:
- id: markdownlint
args: [
--fix,
--disable,
MD024,
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
See the License for the specific language governing permissions and
limitations under the License.
'''
import numpy as np
import logging
from typing import TYPE_CHECKING, Union

import numpy as np
from sostrades_core.execution_engine.sos_wrapp import SoSWrapp

if TYPE_CHECKING:
from sostrades_optimization_plugins.models.differentiable_model import DifferentiableModel
from sostrades_optimization_plugins.models.differentiable_model import (
DifferentiableModel,
)


class AutodifferentiedDisc(SoSWrapp):
Expand Down Expand Up @@ -48,7 +50,6 @@ def get_non_numerical_inputs(self):
inputs = self.get_sosdisc_inputs()
return {key: value for key, value in inputs.items() if value is not None}


def compute_sos_jacobian(self):
"""
Compute jacobian for each coupling variable
Expand All @@ -68,13 +69,12 @@ def compute_sos_jacobian(self):
for c_i_df in coupling_dataframe_input:
all_inputs_model_path.extend(self.model.get_df_input_dotpaths(df_inputname=c_i_df))

all_inputs_model_path = list(filter(lambda x: not x.endswith(f":years"), all_inputs_model_path))
all_inputs_model_path = list(filter(lambda x: not x.endswith(":years"), all_inputs_model_path))

all_outputs_model_path = other_coupling_outputs
for c_o_df in coupling_dataframe_output:
all_outputs_model_path.extend(self.model.get_df_output_dotpaths(df_outputname=c_o_df))
all_outputs_model_path = list(filter(lambda x: not x.endswith(f":years"), all_outputs_model_path))

all_outputs_model_path = list(filter(lambda x: not x.endswith(":years"), all_outputs_model_path))

def handle_gradients_wrt_inputs(output_path: str, gradients: dict):
arg_output = (output_path,)
Expand All @@ -89,12 +89,10 @@ def handle_gradients_wrt_inputs(output_path: str, gradients: dict):
grad_input_value = np.array([[grad_input_value]])
self.set_partial_derivative_for_other_types(arg_output, arg_input, grad_input_value)


for output_path in all_outputs_model_path:
gradients = self.model.compute_partial(output_name=output_path, input_names=all_inputs_model_path)
handle_gradients_wrt_inputs(output_path=output_path, gradients=gradients)


def _auto_configure_jacobian_variables(self):
self.coupling_inputs = []
all_inputs_dict = {**self.DESC_IN, **self.inst_desc_in}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from collections import defaultdict
from copy import deepcopy
from typing import Callable, Union, Any
from typing import Any, Callable, Union

try:
import jax
Expand All @@ -32,7 +32,6 @@
import numpy as np
import numpy.typing as npt
import pandas as pd
from climateeconomics.glossarycore import GlossaryCore

ArrayLike = Union[list[float], npt.NDArray[np.float64]]
InputType = Union[float, int, ArrayLike, pd.DataFrame]
Expand Down
5 changes: 4 additions & 1 deletion sostrades_optimization_plugins/tools/discipline_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
from sostrades_core.tests.core.abstract_jacobian_unit_test import (
AbstractJacobianUnittest,
)
from sostrades_optimization_plugins.models.autodifferentiated_discipline import AutodifferentiedDisc

from sostrades_optimization_plugins.models.autodifferentiated_discipline import (
AutodifferentiedDisc,
)


def discipline_test_function(module_path: str, name: str, model_name: str,
Expand Down

0 comments on commit 4f3e4ed

Please sign in to comment.