Skip to content

Commit 0ab6bb9

Browse files
authored
Add koma CLI app (#769)
* Add KomaMRI CLI app * Bump KomaMRI patch version * Fix CLI app compatibility * Add koma CLI preferences * Cover koma CLI behavior * Use pkg app commands in docs * Use app dev in CLI docs * Cover koma CLI batch paths * Update docs preview metadata
1 parent 8c66f5c commit 0ab6bb9

12 files changed

Lines changed: 733 additions & 67 deletions

File tree

.github/workflows/docs-preview.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ jobs:
120120
const prNumber = Number('${{ steps.pr.outputs.number }}');
121121
const previewUrl = `https://juliahealth.github.io/KomaMRI.jl/previews/PR${prNumber}/`;
122122
const marker = '<!-- komamri-docs-preview-link -->';
123-
const body = `${marker}\nPreview available: ${previewUrl}`;
123+
const previewSha = context.payload.workflow_run.head_sha.slice(0, 7);
124+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
125+
const body = `${marker}\nPreview available: ${previewUrl}\n\nLast preview build: ${previewSha}, [Docs Preview run ${context.runId}](${runUrl})`;
124126
125127
const { data: comments } = await github.rest.issues.listComments({
126128
owner: context.repo.owner,

Project.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
name = "KomaMRI"
22
uuid = "6a340f8b-2cdf-4c04-99be-4953d9b66d0a"
3-
version = "0.10.1"
3+
version = "0.10.2"
44
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
55

66
[workspace]
77
projects = ["test", "docs", "benchmarks", "KomaMRIBase", "KomaMRICore", "KomaMRIFiles", "KomaMRIPlots"]
88

9+
[apps]
10+
koma = { submodule = "CLI", julia_flags = ["--threads=auto"] }
11+
912
[deps]
1013
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
1114
Blink = "ad839575-38b3-5650-b840-f874b8c74a25"
@@ -16,6 +19,8 @@ KomaMRIFiles = "fcf631a6-1c7e-4e88-9e64-b8888386d9dc"
1619
KomaMRIPlots = "76db0263-63f3-4d26-bb9a-5dba378db904"
1720
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
1821
MRIReco = "bdf86e05-2d2b-5731-a332-f3fe1f9e047f"
22+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
23+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1924
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2025

2126
[compat]
@@ -28,5 +33,7 @@ KomaMRIFiles = "0.10"
2833
KomaMRIPlots = "0.11"
2934
MAT = "0.10, 0.11, 0.12"
3035
MRIReco = "0.6, 0.7, 0.8, 0.9"
36+
PrecompileTools = "1"
37+
Preferences = "1"
3138
Reexport = "1"
3239
julia = "1.9"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ To install, just **type** `] add KomaMRI` in the Julia REPL or copy-paste the fo
103103
```julia
104104
pkg> add KomaMRI
105105
pkg> add CUDA # Optional: Install desired GPU backend (CUDA, AMDGPU, Metal, or oneAPI (experimental))
106+
pkg> app add KomaMRI # Optional: Install the koma app (Julia 1.12+)
106107

107108
```
109+
108110
For more information about installation instructions, refer to the section [Getting Started](https://JuliaHealth.github.io/KomaMRI.jl/dev/how-to/1-getting-started) of the documentation.
111+
109112
## First run
110113
KomaMRI.jl features a convenient GUI with predefined simulation inputs (i.e. `Sequence`, `Phantom`, and `Scanner`). To launch the GUI, use the following command:
111114

docs/src/how-to/1-1-use-koma-ui.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ julia> using KomaMRI
2222
2323
julia> KomaUI()
2424
```
25+
After installing the [`koma` app](1-4-use-koma-cli.md#Installing-the-App) (Julia 1.12+), the same interface can be opened from the terminal:
26+
```bash
27+
koma
28+
```
2529
```@raw html
2630
<p align="center"><img width="90%" src="../assets/gui-dashboard.png"/></p>
2731
```
@@ -151,4 +155,3 @@ The variables that update the interface are:
151155
* `img_ui[]` for the **Image**
152156

153157
Don't forget to add the brackets `[]` to these variables, otherwise it won't work.
154-
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Use Koma from the Command Line
2+
3+
KomaMRI provides the `koma` Julia app for opening the UI or running simulations from a terminal.
4+
5+
## Installing the App
6+
7+
Install KomaMRI with `pkg> add KomaMRI`, then install the `koma` app (Julia 1.12+):
8+
```julia-repl
9+
pkg> app add KomaMRI # Julia 1.12+
10+
pkg> # app dev /path/to/KomaMRI.jl # Local checkout, Julia 1.12+
11+
```
12+
13+
The executable is installed in `~/.julia/bin`. If `koma` is not found, add that directory to your `PATH`.
14+
The app command is named `koma`; Julia app names are executable names, not registered package names.
15+
16+
## Basic Workflow & Input Defaults
17+
18+
With no arguments, `koma` opens the graphical interface with default inputs:
19+
```bash
20+
koma
21+
```
22+
23+
Add input files without output paths to preload the UI before it opens:
24+
```bash
25+
koma -i epi.seq brain.phantom
26+
```
27+
28+
Input files can be passed in any order. KomaMRI identifies them by extension: `.seq`, `.phantom` or `.h5`.
29+
A scanner `.sys` file is also accepted, but it does nothing for now.
30+
31+
## Running Simulation
32+
33+
Add a simulation output path with `-o` or `--outputs` to run without opening the UI:
34+
```bash
35+
koma -i epi.seq brain.phantom -o raw.mrd
36+
```
37+
38+
Simulation output can be `.mrd` or `.mat`, selected from the output filename extension.
39+
40+
## Reconstructing Image using MRIReco
41+
42+
Pass a second output path to reconstruct after simulation. Reconstruction output is currently `.mat`:
43+
```bash
44+
koma -i epi.seq brain.phantom -o raw.mrd image.mat
45+
```
46+
47+
Use `_` to skip saving the simulation output:
48+
```bash
49+
koma -i epi.seq brain.phantom -o _ image.mat
50+
```
51+
52+
## Simulation and Reconstruction Parameters
53+
54+
Simulation and reconstruction parameters can be passed as repeated `KEY=VALUE` pairs:
55+
```bash
56+
koma -i epi.seq brain.phantom -s sim_method=BlochMagnus4 -r reco=direct -o raw.mrd
57+
```
58+
59+
The long forms are `--sim-param` and `--recon-param`.
60+
61+
## Backend and Threading
62+
63+
Simulations run on multi-threaded CPU by default. GPU backends can be loaded by name:
64+
```bash
65+
koma -b Metal -i epi.seq brain.phantom -o raw.mrd
66+
```
67+
68+
The selected backend package must be installed in your default Julia environment.
69+
70+
The app starts with CPU threading enabled automatically. To choose a thread count, pass Julia flags before `--` and KomaMRI arguments after it:
71+
```bash
72+
koma --threads=8 -- -i epi.seq brain.phantom -o raw.mrd
73+
```
74+
75+
## Default App Configuration
76+
77+
`koma` can read CLI defaults from Julia's `LocalPreferences.toml` in the app environment. Put the file in the path that matches how the app was installed:
78+
79+
- Installed with `pkg> app add KomaMRI` (Julia 1.12+): `~/.julia/environments/apps/KomaMRI/LocalPreferences.toml`
80+
- Installed with `pkg> app dev /path/to/KomaMRI.jl` (Julia 1.12+): `/path/to/KomaMRI.jl/LocalPreferences.toml`
81+
82+
```toml
83+
[KomaMRI.koma]
84+
backend = "CPU" # CPU, CUDA, Metal, AMDGPU, or oneAPI
85+
86+
[KomaMRI.koma.inputs]
87+
sequence = "mysequence.seq"
88+
phantom = "myphantom.phantom"
89+
90+
[KomaMRI.koma.outputs]
91+
# rawdata = "raw.mrd"
92+
# image = "image.mat"
93+
94+
[KomaMRI.koma.sim_params]
95+
# Numerical accuracy
96+
sim_method = "BlochMagnus4"
97+
precision = "f32"
98+
"Δt" = 1e-3
99+
"Δt_rf" = 5e-5
100+
# Memory
101+
max_block_length = 512
102+
max_rf_block_length = inf
103+
# CPU multi-threaded
104+
Nthreads = 8
105+
# GPU kernel launch config
106+
gpu_groupsize_precession = 256
107+
gpu_groupsize_excitation = 256
108+
```
109+
110+
CLI arguments override these defaults.

docs/src/introduction/1-getting-started.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ This process should take about 5 minutes in a fresh Julia installation. Here is
1616
```julia-repl
1717
julia> ]
1818
19-
(@v1.9) pkg> add KomaMRI
19+
(@v1.12) pkg> add KomaMRI
20+
21+
pkg> app add KomaMRI # Optional: add koma CLI app (Julia 1.12+)
2022
```
2123
Then press `Ctrl+C` or `backspace` to return to the `julia>` prompt.
2224

23-
2425
---
2526
## My First MRI Simulation
2627

@@ -35,6 +36,8 @@ The first time you use this command it may take more time than usual, but a wind
3536

3637
![](../assets/ui-mainpage.png)
3738

39+
The same UI can also be opened from the terminal with the [`koma` app](../how-to/1-4-use-koma-cli.md).
40+
3841
The user interface has some basic definitions for the scanner, phantom, and sequence already preloaded. So you can immediately interact with the simulation and reconstruction processes, and then visualize the results.
3942

4043
As a simple demonstration, press the `Simulate!` button and wait until the simulation is ready. Now you have acquired the `Raw Signal` and you should see the following:

src/KomaApp.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module CLI
2+
3+
import ..KomaMRI: CLI_HELP, run_cli
4+
5+
function print_help()
6+
print(CLI_HELP)
7+
return nothing
8+
end
9+
10+
function (@main)(ARGS)
11+
if length(ARGS) == 1 && ARGS[1] in ("-h", "--help")
12+
return print_help()
13+
end
14+
return run_cli(ARGS)
15+
end
16+
17+
end

0 commit comments

Comments
 (0)