Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ repos:
- id: pylint
files: ^(physics|tools|test)/
additional_dependencies: [numpy]
# translations of canoP studio: every text of the studio has its English translation
- repo: local
hooks:
- id: check-i18n
name: translations of canoP studio
entry: python tools/trame/check_i18n.py
language: python
files: ^tools/
pass_filenames: false
# Fix typos
- repo: https://github.com/crate-ci/typos
rev: v1.23.1
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ The user-visible changes of canoP, by version (see `CONTRIBUTING.md` for the ver

## Unreleased

- canoP studio in English or in French: a FR/EN switch in the top bar, saved in the settings. New
installations start in English; studios set up before keep French.

## 0.1.0 - 2026-11-27

First release of canoP with its physics written in Python. The numbering restarts at 0.1.0.
Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SPDX-License-Identifier = "Apache-2.0 WITH LLVM-exception"

[[annotations]]
path = [
".mcp.json", "tools/vscode/package.json"
".mcp.json", "tools/vscode/package*.json"
]
precedence = "aggregate"
SPDX-FileCopyrightText = "canoP authors"
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A run restarts from an output with `io.restart_enabled = 1` and `io.restart_file
## Initial condition only

`simulation.nstepmax = 0` runs no time step: canoP refines the initial condition level by level up
to `amr.max_refine` and writes it. The **Condition initiale** button of canoP studio does this
to `amr.max_refine` and writes it. The **Initial condition** button of canoP studio does this
without touching the run ({doc}`../user-guide/studio`).

## Physics directory
Expand Down
18 changes: 9 additions & 9 deletions docs/user-guide/campaigns.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The runs of the **Run** tab belong to the campaign `hors-campagne`.

## Making and launching a campaign

In the **Campagne** tab, give a name, a base input file and one line per varied parameter:
In the **Campaign** tab, give a name, a base input file and one line per varied parameter:

```text
simulation.cfl = 0.4, 0.6, 0.8
Expand All @@ -23,14 +23,14 @@ launch.nprocs = 4, 8

The campaign holds one run per combination (here 18). `launch.*` keys vary the execution of the run
(`nprocs`, `omp_threads`, `nodes`, `time`, `partition`, `gpus_per_task`) instead of its input file.
Runs can be added later. **Lancer les runs préparés** submits the prepared runs as Slurm jobs
Runs can be added later. **Launch the prepared runs** submits the prepared runs as Slurm jobs
(signac-flow, `project.py` of the campaign). Before submitting, the studio checks the limits set in
its settings: runs per submission, runs per campaign, nodes, cores and GPUs per run, core-hours and
GPU-hours per submission.

The table of the campaign shows the state of each run (préparé, en file, en cours, terminé,
interrompu, échoué), its parameters and its metrics; a run can be shown in the Visualisation or loaded
in the editor of the Run tab. `analysis.py` of the campaign defines the plots of the **Analyse** tab.
The table of the campaign shows the state of each run (prepared, queued, running, finished,
interrupted, failed), its parameters and its metrics; a run can be shown in the View tab or loaded in
the editor of the Run tab. `analysis.py` of the campaign defines the plots of the **Analysis** tab.

## Physics and versioning

Expand All @@ -53,13 +53,13 @@ studio.

The `README.md` of each campaign explains it: build canoP at the commit written in the input files,
clone the repository of the campaign into `_campaigns/<campaign>` of that canoP (switch to a branch
to start from an older commit), then **Préparer à nouveau** puts back the runs submitted in the
original campaign in the prepared state, and **Lancer les runs préparés** runs them again.
to start from an older commit), then **Prepare again** puts back the runs submitted in the
original campaign in the prepared state, and **Launch the prepared runs** runs them again.

## Initial condition only

The **Condition initiale** button of the Run tab runs the input file of the editor without any time
step (`simulation.nstepmax = 0`) and shows the refined initial condition in the Visualisation. The run
The **Initial condition** button of the Run tab runs the input file of the editor without any time
step (`simulation.nstepmax = 0`) and shows the refined initial condition in the View tab. The run
is not launched and nothing is committed: the output goes to `<run>/condition_initiale/` (ignored by
the repository of the campaign), with the current physics of the campaign. **Revenir au run** shows the
outputs of the run again.
17 changes: 9 additions & 8 deletions docs/user-guide/studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

canoP studio is a web application, built with [trame](https://kitware.github.io/trame/), to prepare,
build, run and look at canoP simulations from a browser. It runs on a login node: the meshes are drawn
by the browser (vtk.js), the server needs neither a GPU nor OpenGL. Its interface is in French.
by the browser (vtk.js), the server needs neither a GPU nor OpenGL. Its interface is in English or
French: the FR/EN switch of the top bar, saved in its settings (new installations start in English).

- **Run**: load an example of `settings/` or the input file of a run, edit it key by key or as
text. Each key shows, under the mouse, its role, its type, its default value and, for the options
of the model, the valid values and the summary of the chosen file; keys that canoP never reads are
flagged. Launch the run, or compute only its refined initial
condition (**Condition initiale**).
- **Campagne**: parameter studies, see {doc}`campaigns`.
- **Visualisation**: fields and colour maps, the AMR mesh, velocity arrows, streamlines, time
condition (**Initial condition**).
- **Campaign**: parameter studies, see {doc}`campaigns`.
- **View**: fields and colour maps, the AMR mesh, velocity arrows, streamlines, time
slider, slices or outer surface in 3D, updated while the run writes its outputs. The view and the
derived fields of each run are Python files of the run (`canoP_view.py`, `canoP_fields.py`),
reloaded when they are saved.
- **Journal**: the logs of the build and of the run, while they are written.
- **Analyse**: the analysis of a campaign (`analysis.py` of the campaign).
- **Log**: the logs of the build and of the run, while they are written.
- **Analysis**: the analysis of a campaign (`analysis.py` of the campaign).

The settings panel holds the build settings (sources, build directory, dimension, Kokkos backend and
architectures, environment, CMake options, build on this node or as a Slurm job) and the run settings
Expand Down Expand Up @@ -86,8 +87,8 @@ in `<canoP>/.local/canop-studio/venv` when `.local/canop-studio` exists, else in
The script prints the addresses to open, with a key:

```text
via code-server : http://127.0.0.1:8080/proxy/8090/index.html?secret=...
direct : http://localhost:8090/index.html?secret=...
via code-server: http://127.0.0.1:8080/proxy/8090/index.html?secret=...
direct: http://localhost:8090/index.html?secret=...
```

From code-server on the same node, open the first one. Otherwise open an ssh tunnel
Expand Down
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Tests of canoP (ctest):
#
# * unit tests of the limiters and the settings (label "unit"), see unit/;
# * unit tests of the limiters and the settings (label "unit"), see unit/, and the check of the
# translations of canoP studio (label "unit"), tools/trame/check_i18n.py;
# * regression tests: short runs compared with stored reference outputs (label "regression", and
# "3d" for the 3D cases), see regression/regression.py and regression/cases.py;
# * physical properties without reference outputs (label "physics"), see physics/physics.py.
Expand All @@ -15,6 +16,10 @@ if(NOT Python3_Interpreter_FOUND)
return()
endif()

# translations of canoP studio: every text of the studio has its English translation
add_test(NAME studio_i18n COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/trame/check_i18n.py)
set_tests_properties(studio_i18n PROPERTIES LABELS unit)

# physical properties without reference outputs (label "physics"), with canoP_2d
foreach(CHECK outflow mirror energy)
add_test(
Expand Down
34 changes: 20 additions & 14 deletions tools/canop_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import time
from dataclasses import asdict, dataclass, field, fields

from canop_i18n import DEFAULT_LANGUAGE, LANGUAGES, tr

# this file lives in <canoP>/tools
DEFAULT_SOURCE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -704,9 +706,13 @@ class Settings:
camp_max_core_hours: int = 100 # core-hours requested by a submission (cores x Slurm time)
camp_max_gpus: int = 4 # GPUs of a run
camp_max_gpu_hours: int = 50 # GPU-hours requested by a submission
# language of the studio, 'en' or 'fr' (canop_i18n); settings saved without it are in French
language: str = DEFAULT_LANGUAGE

def __post_init__(self):
"""Replace invalid values by defaults and keep the profiles of the pykokkos backends only."""
if self.language not in LANGUAGES:
self.language = DEFAULT_LANGUAGE
try:
self.dim = int(self.dim)
except (TypeError, ValueError):
Expand Down Expand Up @@ -1257,14 +1263,14 @@ def slurm_partitions_info():


def _duration(seconds):
"""A time limit as shown to the user, in French: 30 min, 1 h, 1 j 12 h, sans limite."""
"""A time limit as shown to the user, in the language of the studio: 30 min, 1 h, 1 j 12 h, sans limite."""
if seconds == float("inf"):
return "sans limite"
return tr("sans limite")
d, r = divmod(int(seconds), 86400)
h, r = divmod(r, 3600)
m = r // 60
return " ".join(x for x in ("%d j" % d if d else "", "%d h" % h if h else "", "%d min" % m if m else "") if x) \
or "0 min"
return " ".join(x for x in (tr("%d j") % d if d else "", "%d h" % h if h else "", "%d min" % m if m else "")
if x) or "0 min"


def slurm_partitions():
Expand All @@ -1273,18 +1279,18 @@ def slurm_partitions():


def slurm_partitions_text():
"""One line per Slurm partition with its limits, or [] without Slurm.
"""One line per Slurm partition with its limits, in the language of the studio, or [] without Slurm.

E.g. 'gpua100 : 1 j max, 9 nœuds de 32 cœurs, 4 GPU par nœud'; the default partition is marked by *.
"""
out = []
for p in slurm_partitions_info():
words = ["%s max" % _duration(p["seconds"])]
if p["nodes"] and p["cpus"]:
words.append("%s nœuds de %s cœurs" % (p["nodes"], p["cpus"]))
words.append(tr("%s nœuds de %s cœurs") % (p["nodes"], p["cpus"]))
if p["gpus"]:
words.append("%d GPU par nœud" % p["gpus"])
out.append("%s%s : %s" % (p["name"], " *" if p["default"] else "", ", ".join(words)))
words.append(tr("%d GPU par nœud") % p["gpus"])
out.append(tr("%s%s : %s") % (p["name"], " *" if p["default"] else "", ", ".join(words)))
return out


Expand All @@ -1309,7 +1315,7 @@ def slurm_jobs_alive(root):


def clear_directory(path, source):
"""Delete everything inside `path`, keeping the directory itself; return (ok, message).
"""Delete everything inside `path`, keeping the directory itself; return (ok, message in the studio's language).

Refused for /, the home directory, a directory that holds the sources, and a directory with
active Slurm jobs.
Expand All @@ -1318,12 +1324,12 @@ def clear_directory(path, source):
source = os.path.realpath(source)
home = os.path.realpath(os.path.expanduser("~"))
if not os.path.isdir(path):
return True, "%s n'existe pas, rien à supprimer" % path
return True, tr("%s n'existe pas, rien à supprimer") % path
if path in ("/", home) or path == source or source.startswith(path + os.sep):
return False, "refusé : %s contient les sources ou est un répertoire système" % path
return False, tr("refusé : %s contient les sources ou est un répertoire système") % path
jobs = slurm_jobs_alive(path)
if jobs:
return False, "refusé : job(s) Slurm encore actif(s) dans %s : %s" % (path, ", ".join(jobs))
return False, tr("refusé : job(s) Slurm encore actif(s) dans %s : %s") % (path, ", ".join(jobs))
errors = []
for name in os.listdir(path):
entry = os.path.join(path, name)
Expand All @@ -1335,8 +1341,8 @@ def clear_directory(path, source):
except OSError as err:
errors.append(str(err))
if errors:
return False, "suppression incomplète dans %s : %s" % (path, errors[0])
return True, "%s vidé" % path
return False, tr("suppression incomplète dans %s : %s") % (path, errors[0])
return True, tr("%s vidé") % path


def xdmf_complete(path):
Expand Down
52 changes: 52 additions & 0 deletions tools/canop_i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SPDX-FileCopyrightText: 2026 canoP authors
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Language of the texts of canoP studio: French or English.

The texts are written in French in the code, wrapped in tr(); their English translations are in
canop_i18n_en.py (EN, French text -> English text). tr() returns the text in the current language,
chosen in the studio (setting `language`), so a text must be translated when it is shown, not when
a module is imported: module-level constants and state values set once are recomputed when the
language changes (refresh_language() of the modules of the studio).

A translation keeps the placeholders of the text (%s, %d, %(name)s, {{ ... }}), and, for a text that
is part of a JavaScript expression, its quotes: tools/trame/check_i18n.py checks both, and that every
text wrapped in tr() has a translation.
"""
import json

from canop_i18n_en import EN

LANGUAGES = ("en", "fr")
DEFAULT_LANGUAGE = "en" # new installations; settings saved before the choice existed are in French

_current = {"language": DEFAULT_LANGUAGE}


def set_language(language):
"""Choose the language of the texts ('en' or 'fr'; anything else: the default)."""
_current["language"] = language if language in LANGUAGES else DEFAULT_LANGUAGE


def language():
"""Current language of the texts."""
return _current["language"]


def tr(text):
"""`text` (French, as written in the code) in the current language."""
if _current["language"] == "en":
return EN.get(text, text)
return text


def tr_js(text):
"""tr(text) as a single-quoted JavaScript string literal, for a text inside an expression of the page.

Safe inside {{ }} and in a bound attribute (label=("... + %s" % tr_js(...),)), which trame writes
as :label="<expression>" without escaping: no double quote, no & nor < > in the literal.
"""
escaped = json.dumps(tr(text), ensure_ascii=False)[1:-1].replace('\\"', '"') # JSON escapes, unquoted
for char, code in (("'", "\\u0027"), ('"', "\\u0022"), ("&", "\\u0026"), ("<", "\\u003c"), (">", "\\u003e")):
escaped = escaped.replace(char, code)
return "'" + escaped + "'"
Loading
Loading