Skip to content

[ana6, com8]: Add ana6Optimisation Module, apply changes in com8MoTPSA#1245

Open
RolandFischbacher wants to merge 1 commit intomasterfrom
RF_com8MoTPSA
Open

[ana6, com8]: Add ana6Optimisation Module, apply changes in com8MoTPSA#1245
RolandFischbacher wants to merge 1 commit intomasterfrom
RF_com8MoTPSA

Conversation

@RolandFischbacher
Copy link
Contributor

This PR introduces a new optimisation module ana6Optimisation for com8MoTPSA and updates the simulation workflow.


The module ana6Optimisation includes:

  • Calculation of combined loss function (runout + tversky)
  • Morris sensitivity analysis for parameter ranking
  • Sequential and non-sequential surrogate based optimisation routines

New files in ana6Opitmisaton:

  • runMorrisSA.py (configuration: runMorrisSACfg.ini)
  • runPlotMorrisConvergence.py (uses runMorrisSACfg.ini)
  • runOptimisation.py (configuration: runOptimisationCfg.ini)
  • optimisationUtils.py
  • README_ana6.md (contains usage instructions)

New file in out3Plot:

  • outAna6Plots.py

Changed workflow of runing com8MoTPSA:

  • Check prior if simulation is run already
  • Process in chunks not all simulations at once

@RolandFischbacher RolandFischbacher self-assigned this Feb 23, 2026
@RolandFischbacher RolandFischbacher added the enhancement New feature or request label Feb 23, 2026
@qltysh
Copy link
Contributor

qltysh bot commented Feb 23, 2026

❌ 10 blocking issues (18 total)

Tool Category Rule Count
prettier Style Incorrect formatting, autoformat by running qlty fmt. 7
ripgrep Lint # NOTE: rmse/mae were returned as NEGATIVE numbers because the higher is better internally 1
ruff Lint f-string without any placeholders 1
ruff Lint Local variable bars is assigned to but never used 1
qlty Structure Function with high complexity (count = 20): readParamSetDF 4
qlty Structure Deeply nested control flow (level = 4) 2
qlty Structure High total complexity (count = 82) 1
qlty Structure Function with many returns (count = 6): formatSig 1

@qltysh one-click actions:

  • Auto-fix formatting (qlty fmt && git push)

# 4) Plot
x = np.arange(len(df))
fig, ax = plt.subplots(figsize=(12, 6))
bars = ax.bar(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local variable bars is assigned to but never used [ruff:F841]

Suggested change
bars = ax.bar(
ax.bar(

tmp.insert(0, "table", t)
frames.append(tmp)
pd.concat(frames, ignore_index=True).to_csv(csv_path, index=False)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with high complexity (count = 36): saveTopCandidates [qlty:function-complexity]

return f"{x:.2e}" # small numbers in scientific notation
elif abs(x) < 100:
return f"{x:.2g}" # 2 significant digits
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many returns (count = 6): formatSig [qlty:return-statements]

fig.tight_layout()

if outpath is not None:
fig.savefig(outpath, dpi=300, bbox_inches="tight")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High total complexity (count = 82) [qlty:file-complexity]

@@ -0,0 +1,895 @@
import numpy as np
Copy link
Contributor

@qltysh qltysh bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. Incorrect formatting, autoformat by running qlty fmt. [black:fmt]


2. Incorrect formatting, autoformat by running qlty fmt. [ruff:fmt]

@@ -0,0 +1,918 @@
import numpy as np
Copy link
Contributor

@qltysh qltysh bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. Incorrect formatting, autoformat by running qlty fmt. [black:fmt]


2. Incorrect formatting, autoformat by running qlty fmt. [ruff:fmt]

@fso42 fso42 added this to the Version 2.0 milestone Feb 23, 2026
@fso42 fso42 changed the title [ana6Opitmisation], [com8MoTPSA]: Add ana6Optimisation Module, apply changes in com8MoTPSA [ana6, com8]: Add ana6Optimisation Module, apply changes in com8MoTPSA Feb 24, 2026
index = config['VISUALISATION']['scenario']
if 'sampleMethod' in config['VISUALISATION']:
sampleMethod = config['VISUALISATION']['sampleMethod']
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deeply nested control flow (level = 4) [qlty:nested-control-flow]

@@ -0,0 +1,140 @@
# ana6 – Sensitivity Analysis & Optimisation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect formatting, autoformat by running qlty fmt. [prettier:fmt]

'parameterSet': paramSet, # [row for row in paramSet], # Wrap each row as a list
'order': pd.to_numeric(order), # convert to int
'sampleMethods': sampleMethods
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with high complexity (count = 20): readParamSetDF [qlty:function-complexity]

@fso42 fso42 assigned fso42 and unassigned RolandFischbacher Feb 24, 2026
Squash of 20 commits from RF_com8MoTPSA branch including:
- com8MoTPSA workflow improvements (chunked multiprocessing, path handling)
- Bayesian optimisation integration (ana6Optimisation module)
- Morris sensitivity analysis scripts
- AIMEC runout reference implementation
- probAna pickle saving and bounds
- Plotting and config improvements
error_score="raise" # fail fast if something else is wrong
)

# NOTE: rmse/mae were returned as NEGATIVE numbers because the higher is better internally
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# NOTE: rmse/mae were returned as NEGATIVE numbers because the higher is better internally [ripgrep:NOTE]

print(f"📊 sigma: {best_sigma:.4f}")

return {
f"TopNBest": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string without any placeholders [ruff:F541]

Suggested change
f"TopNBest": {
"TopNBest": {

# Delete folder in Work directory after postprocessing to reduce memory costs
avaDir = cfgMain["MAIN"]["avalancheDir"]
for sim in simNamesChunk:
folderName = "Work/com8MoTPSA/" + sim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deeply nested control flow (level = 4) [qlty:nested-control-flow]


# Postprocess the simulations
com8MoTPSAPostprocess(simDict, cfgMain, inputSimFiles)
if returnSimName is not None and simDict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with high complexity (count = 18): com8MoTPSAMain [qlty:function-complexity]

@qltysh
Copy link
Contributor

qltysh bot commented Feb 24, 2026

Qlty

Coverage Impact

⬇️ Merging this pull request will decrease total coverage on master by 0.19%.

Modified Components (1)

RatingComponent% Diff
Coverage rating: C Coverage rating: C
com1DFA

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: F Coverage rating: F
avaframe/com8MoTPSA/com8MoTPSA.py0.0%21-182
Coverage rating: A Coverage rating: A
avaframe/in3Utils/cfgUtils.py71.4%995, 1016
Total10.0%
🤖 Increase coverage with AI coding...

In the `RF_com8MoTPSA` branch, add test coverage for this new code:

- `avaframe/com8MoTPSA/com8MoTPSA.py` -- Line 21-182
- `avaframe/in3Utils/cfgUtils.py` -- Lines 995 and 1016

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@fso42 fso42 assigned RolandFischbacher and unassigned fso42 Feb 24, 2026
Comment on lines +64 to +68
if modName in ["com1DFA", "com5SnowSlide", "com6RockAvalanche", "com8MoTPSA", "com9MoTVoellmy"]:
# load dataFrame for all configurations of simulations in avalancheDir
simDF = cfgUtils.createConfigurationInfo(avalancheDir)
# create data frame that lists all available simulations and path to their result type result files
inputsDF, resTypeList = fU.makeSimFromResDF(avalancheDir, "com1DFA")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously "com8MoTPSA" was not in if modName in [...], com1DFA is hard coded, thus not work for com8MoTPSA
removing com8MoTPSA works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants