Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple docs warnings #258

Merged
merged 8 commits into from
Dec 21, 2023
2 changes: 0 additions & 2 deletions KomaMRICore/src/KomaMRICore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export Grad, RF, ADC, Delay
export Mag, dur
#Phantom
export brain_phantom2D, brain_phantom3D
#Spinors
export Spinor, Rx, Ry, Rz, Q, Un
#Secondary
export get_kspace, rotx, roty, rotz
#ISMRMRD
Expand Down
24 changes: 18 additions & 6 deletions KomaMRICore/src/simulation/GPUFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function print_gpus()
check_use_cuda()
if use_cuda[]
cuda_devices = [Symbol("($(i-1)$(i == 1 ? "*" : " "))") => name(d) for (i,d) = enumerate(devices())]
@info "$(length(devices())) CUDA capable device(s)." cuda_devices...
@info "$(length(devices())) CUDA capable device(s)." cuda_devices...
else
@info "0 CUDA capable devices(s)."
end
return
return
end

"""
Expand Down Expand Up @@ -47,7 +47,11 @@ adapt_storage(to::KomaCUDAAdaptor, x) = CUDA.cu(x)

Tries to move `x` to the current GPU device. Inspired by Flux's `gpu` function.

This works for functions, and any struct marked with [`@functor`](@ref).
This works for functions, and any struct marked with `@functor`.

Use [`cpu`](@ref) to copy back to ordinary `Array`s.

See also [`f32`](@ref) and [`f64`](@ref) to change element type only.

# Examples
```julia
Expand All @@ -70,7 +74,9 @@ adapt_storage(to::KomaCPUAdaptor, x::AbstractRange) = x

Tries to move object to CPU. Inspired by Flux's `cpu` function.

This works for functions, and any struct marked with [`@functor`](@ref).
This works for functions, and any struct marked with `@functor`.

See also [`gpu`](@ref).

# Examples
```julia
Expand All @@ -88,15 +94,21 @@ adapt_storage(T::Type{<:Real}, xs::AbstractArray{<:Bool}) = xs #Type piracy

"""
f32(m)

Converts the `eltype` of model's parameters to `Float32`
Recurses into structs marked with [`@functor`](@ref).
Recurses into structs marked with `@functor`.

See also [`f64`](@ref).
"""
f32(m) = paramtype(Float32, m)

"""
f64(m)

Converts the `eltype` of model's parameters to `Float64` (which is Koma's default)..
Recurses into structs marked with [`@functor`](@ref).
Recurses into structs marked with `@functor`.

See also [`f32`](@ref).
"""
f64(m) = paramtype(Float64, m)

Expand Down
35 changes: 34 additions & 1 deletion KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,40 @@ include("Bloch/BlochSimulationMethod.jl") #Defines Bloch simulation method
include("Bloch/BlochDictSimulationMethod.jl") #Defines BlochDict simulation method

"""
Returns a dictionary with default simulation parameters.
sim_params = default_sim_params(sim_params=Dict{String,Any}())

This function returns a dictionary containing default simulation parameters while also
allowing the user to define some of them.

# Arguments
- `sim_params`: (`::Dict{String,Any}`, `=Dict{String,Any}()`) user-defined dictionary with
simulation parameters. The following lists its keys along with their possible values:
* "return_type": defines the output of the [`simulate`](@ref) function. Possible values
are `"raw"`, `"mat"`, and `"state"`, corresponding to outputting a MRIReco
`RawAcquisitionData`, the signal values, and the last magnetization state of the
simulation, respectively
* "sim_method": defines the type of simulation. The default value is `Bloch()`, but you
can alternatively use the `BlochDict()` simulation method. Moreover, you have the
flexibility to create your own methods without altering the KomaMRI source code
* "Δt": raster time for gradients
* "Δt_rf": raster time for RFs
* "precision": defines the floating-point simulation precision. You can choose between
`"f32"` and `"f64"` to use `Float32` and `Float64` primitive types, respectively.
It's important to note that, especially for GPU operations, using `"f32"` is
generally much faster
* "Nblocks": divides the simulation into a specified number of time blocks. This parameter
is designed to conserve RAM resources, as **KomaMRI** computes a series of
simulations consecutively, each with the specified number of blocks determined by
the value of `"Nblocks"`
* "Nthreads": divides the **Phantom** into a specified number of threads. Because spins
are modeled independently of each other, **KomaMRI** can solve simulations in
parallel threads, speeding up the execution time
* "gpu": is a boolean that determines whether to use GPU or CPU hardware resources, as
long as they are available on the host computer
* "gpu_device": sets the index ID of the available GPU in the host computer

# Returns
- `sim_params`: (`::Dict{String,Any}`) dictionary with simulation parameters
"""
function default_sim_params(sim_params=Dict{String,Any}())
get!(sim_params, "gpu", true); if sim_params["gpu"] check_use_cuda(); sim_params["gpu"] &= use_cuda[] end
Expand Down
2 changes: 2 additions & 0 deletions KomaMRICore/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ end
end

@testitem "Spinors×Mag" tags=[:core] begin
using KomaMRICore: Spinor, Rx, Ry, Rz, Q, Un

# Spinor 2x2 representation should be equivalent to a 3x1 vector rotation
x = rand(3); x = x./sum(x)
θ = rand() * π
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ makedocs(
modules = [KomaMRI, KomaMRICore, KomaMRIFiles, KomaMRIPlots],
sitename = "KomaMRI.jl: General MRI simulation framework",
authors = "Boris Orostica Navarrete and Carlos Castillo Passi",
checkdocs = :exports,
pages = [
"Home" => "index.md";
"Getting Started" => "getting-started.md";
Expand Down
133 changes: 121 additions & 12 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,66 @@ ADC
Delay
```

## Read Data

```@meta
CurrentModule = KomaMRIFiles
## Sequence-related Functions

### `dur`
```@docs
dur
```

### `read_seq`
### `rotx`
```@docs
read_seq
rotx
```

### `read_phantom_jemris`
### `roty`
```@docs
read_phantom_jemris
roty
```

### `read_phantom_MRiLab`
### `rotz`
```@docs
read_phantom_MRiLab
rotz
```

### `signal_to_raw_data`
### `get_kspace`
```@docs
signal_to_raw_data
get_kspace
```

## Pulse Design
### `get_M1`
```@docs
get_M1
```

### `get_M2`
```@docs
get_M2
```

### `get_flip_angles`
```@docs
get_flip_angles
```

### `is_RF_on`
```@docs
is_RF_on
```

### `is_GR_on`
```@docs
is_GR_on
```

### `is_ADC_on`
```@docs
is_ADC_on
```


## Prebuilt Sequence Building Blocks

```@meta
CurrentModule = KomaMRICore
Expand Down Expand Up @@ -167,8 +200,63 @@ PulseDesigner.spiral_base
PulseDesigner.EPI_example
```


## Input/Output

```@meta
CurrentModule = KomaMRIFiles
```

### `read_seq`
```@docs
read_seq
```

### `read_phantom_jemris`
```@docs
read_phantom_jemris
```

### `read_phantom_MRiLab`
```@docs
read_phantom_MRiLab
```


## Functor Functions

```@meta
CurrentModule = KomaMRICore
```

### `f32`
```@docs
f32
```

### `f64`
```@docs
f64
```

### `cpu`
```@docs
cpu
```

### `gpu`
```@docs
gpu
```


## Simulation

### `default_sim_params`
```@docs
default_sim_params
```

cncastillo marked this conversation as resolved.
Show resolved Hide resolved
### `simulate`
```@docs
simulate
Expand All @@ -179,6 +267,17 @@ simulate
simulate_slice_profile
```

### `signal_to_raw_data`
```@docs
signal_to_raw_data
```

### `Mag`
```@docs
Mag
```


## Plots

```@meta
Expand Down Expand Up @@ -235,6 +334,16 @@ plot_signal
plot_image
```

### `plot_dict`
```@docs
plot_dict
```

### `plot_seqd`
```@docs
plot_seqd
```


## UI

Expand Down
2 changes: 1 addition & 1 deletion docs/src/create-your-own-phantom.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ T2 = T2*1e-3
T2s = T2s*1e-3
```

Finally, we can invoke the [`Phantom`](@Ref) constructor. However, before doing so, we choose not to store spins where the proton density is zero to avoid unnecessary data storage. This is achieved by applying the mask `ρ.!=0` to the arrays. Additionally, please note that we set the z-position array filled with zeros.
Finally, we can invoke the [`Phantom`](@ref) constructor. However, before doing so, we choose not to store spins where the proton density is zero to avoid unnecessary data storage. This is achieved by applying the mask `ρ.!=0` to the arrays. Additionally, please note that we set the z-position array filled with zeros.
```julia
# Define the phantom
obj = Phantom{Float64}(
Expand Down
Loading