Skip to content

Commit f3a08af

Browse files
author
b4pm-devops
committed
merge post_integration to validation
2 parents e2d76dd + 933c757 commit f3a08af

File tree

5 files changed

+1207
-0
lines changed

5 files changed

+1207
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
repos:
2+
- repo: https://github.com/b4pm-devops/sostrades-pre-commit.git
3+
rev: v1.1.2
4+
hooks:
5+
- id: update-headers
6+
- repo: https://github.com/astral-sh/ruff-pre-commit
7+
rev: v0.5.0
8+
hooks:
9+
- id: ruff
10+
args: [
11+
--fix,
12+
--preview,
13+
--exit-non-zero-on-fix,
14+
--config=ruff.toml,
15+
]
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.5.0
18+
hooks:
19+
- id: trailing-whitespace
20+
- id: end-of-file-fixer
21+
exclude: LICENSES/headers
22+
- id: check-yaml
23+
# !reference is specific to gitlab
24+
# !! prefix is specific to mkdocs
25+
exclude: \.gitlab-ci.yml|mkdocs.yml
26+
- id: check-added-large-files
27+
- id: check-json
28+
- id: pretty-format-json
29+
args: [
30+
--autofix,
31+
--no-sort-keys,
32+
]
33+
exclude: \.ipynb
34+
- id: check-toml
35+
- id: destroyed-symlinks
36+
- id: check-symlinks
37+
- repo: https://github.com/pre-commit/pygrep-hooks
38+
rev: v1.10.0
39+
hooks:
40+
- id: rst-backticks
41+
- id: rst-directive-colons
42+
- id: rst-inline-touching-normal
43+
- repo: https://github.com/kynan/nbstripout
44+
rev: 0.7.1
45+
hooks:
46+
- id: nbstripout
47+
- repo: https://github.com/igorshubovych/markdownlint-cli
48+
rev: v0.39.0
49+
hooks:
50+
- id: markdownlint
51+
args: [
52+
--fix,
53+
--disable,
54+
MD024,
55+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'''
2+
Copyright 2024 Capgemini
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
'''
16+
import logging
17+
from typing import TYPE_CHECKING, Union
18+
19+
from sostrades_core.execution_engine.sos_wrapp import SoSWrapp
20+
21+
if TYPE_CHECKING:
22+
from sostrades_optimization_plugins.models.differentiable_model import (
23+
DifferentiableModel,
24+
)
25+
26+
27+
class AutodifferentiedDisc(SoSWrapp):
28+
"""Discipline which model is a DifferentiableModel"""
29+
coupling_inputs = [] # inputs verified during jacobian test
30+
coupling_outputs = [] # outputs verified during jacobian test
31+
32+
def __init__(self, sos_name, logger: logging.Logger):
33+
super().__init__(sos_name, logger)
34+
self.model: Union[DifferentiableModel, None] = None
35+
36+
def run(self):
37+
38+
inputs = self.get_sosdisc_inputs()
39+
self.model.set_inputs(inputs)
40+
outputs = self.model.compute()
41+
self.store_sos_outputs_values(outputs)
42+
43+
def compute_sos_jacobian(self):
44+
"""
45+
Compute jacobian for each coupling variable
46+
"""
47+
48+
gradients = self.model.compute_jacobians_custom(outputs=self.coupling_outputs, inputs=self.coupling_inputs)
49+
for output_name in gradients:
50+
for output_col in gradients[output_name]:
51+
for input_name in gradients[output_name][output_col]:
52+
for input_col, value in gradients[output_name][output_col][input_name].items():
53+
self.set_partial_derivative_for_other_types(
54+
(output_name, output_col),
55+
(input_name, input_col),
56+
value)

0 commit comments

Comments
 (0)