Skip to content

Commit

Permalink
Merge branch 'master' into 3D_recon
Browse files Browse the repository at this point in the history
Conflicts: (fixed)
KomaMRICore/src/rawdata/ISMRMRD.jl

Changes to be committed:
modified:   KomaMRIBase/Project.toml
modified:   KomaMRIBase/src/KomaMRIBase.jl
modified:   KomaMRICore/Project.toml
modified:   KomaMRICore/src/KomaMRICore.jl
modified:   KomaMRICore/src/rawdata/ISMRMRD.jl
modified:   KomaMRICore/src/simulation/SimulatorCore.jl
modified:   KomaMRICore/test/Project.toml
deleted:    KomaMRICore/test/initialize.jl
new file:   KomaMRICore/test/initialize_backend.jl
modified:   KomaMRICore/test/runtests.jl
modified:   KomaMRIFiles/Project.toml
modified:   KomaMRIFiles/src/KomaMRIFiles.jl
modified:   KomaMRIFiles/src/Phantom/Phantom.jl
modified:   KomaMRIPlots/Project.toml
modified:   KomaMRIPlots/src/KomaMRIPlots.jl
modified:   Project.toml
modified:   src/KomaMRI.jl
modified:   src/KomaUI.jl
  • Loading branch information
curtcorum committed Jul 16, 2024
2 parents af870bd + 454e0d6 commit c8e76fb
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 101 deletions.
4 changes: 1 addition & 3 deletions KomaMRIBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
MRIBase = "f7771a9a-6e57-4e71-863b-6e4b6a2f17df"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
Interpolations = "0.13, 0.14, 0.15"
MAT = "0.10"
MRIBase = "0.4"
Parameters = "0.12"
Pkg = "1.4"
Reexport = "1"
julia = "1.9"

[workspace]
projects = ["test"]
projects = ["test"]
6 changes: 0 additions & 6 deletions KomaMRIBase/src/KomaMRIBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,4 @@ export get_Mk, get_kspace, get_M0, get_M1, get_M2
include("sequences/PulseDesigner.jl")
export PulseDesigner

#Package version, KomaMRIBase.__VERSION__
using Pkg
__VERSION__ = VersionNumber(
Pkg.TOML.parsefile(joinpath(@__DIR__, "..", "Project.toml"))["version"]
)

end # module KomaMRIBase
6 changes: 2 additions & 4 deletions KomaMRICore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
Expand All @@ -26,19 +25,18 @@ KomaMetalExt = "Metal"
KomaoneAPIExt = "oneAPI"

[compat]
Adapt = "3, 4"
AMDGPU = "0.9"
Adapt = "3, 4"
CUDA = "3, 4, 5"
Functors = "0.4"
KernelAbstractions = "0.9"
KomaMRIBase = "0.9"
Metal = "1"
oneAPI = "1"
Pkg = "1.4"
ProgressMeter = "1"
Reexport = "1"
ThreadsX = "0.1"
julia = "1.9"
oneAPI = "1"

[workspace]
projects = ["test"]
4 changes: 0 additions & 4 deletions KomaMRICore/src/KomaMRICore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ export simulate, simulate_slice_profile, default_sim_params
# Spinors
export Spinor, Rx, Ry, Rz, Q, Un

#Package version, KomaMRICore.__VERSION__
using Pkg
__VERSION__ = VersionNumber(Pkg.TOML.parsefile(joinpath(@__DIR__, "..", "Project.toml"))["version"])

end
7 changes: 3 additions & 4 deletions KomaMRICore/src/rawdata/ISMRMRD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ function signal_to_raw_data(
phantom_name="Phantom", sys=Scanner(), sim_params=Dict{String,Any}(), ndims=2, use_ndseq=true
)
version = string(VersionNumber(Pkg.TOML.parsefile(joinpath(@__DIR__, "..", "..", "Project.toml"))["version"]))

#Estimate sequence reconstruction dimension, using seq.DEF and potentially other information
#Number of samples and FOV
Nd_seq, Nx, Ny, Nz, Ns, FOVx, FOVy, FOVz, Δx, ktraj = estimate_seq_recon_dimension(seq; sim_params)
if use_ndseq
if ndims != Nd_seq; @warn("Using estimated dimension of $Nd_seq for .mrd file."); ndims = Nd_seq; end
Expand Down Expand Up @@ -204,7 +203,7 @@ function signal_to_raw_data(
Float32.((0, 0, 0)), #patient_table_position float32x3: Patient table off-center
EncodingCounters( #idx uint16x17: Encoding loop counters
UInt16(ny), #kspace_encode_step_1 uint16: e.g. phase encoding line number
UInt16(nz), #kspace_encode_step_2 uint16: e.g. partition encoding number
UInt16(nz), #slice uint16: e.g. imaging slice number
UInt16(0), #average uint16: e.g. signal average number
UInt16(ns), #slice uint16: e.g. imaging slice number
UInt16(0), #contrast uint16: e.g. echo number in multi-echo
Expand All @@ -231,7 +230,7 @@ function signal_to_raw_data(
end
ny = ny % Ny
if scan_counter % NroPerPE2 == 0
nz += 1 #another kspace_encode_step_2
nz += 1 #another image
end
nz = nz % Nz
if scan_counter % NroPerSlice == 0
Expand Down
2 changes: 1 addition & 1 deletion KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function simulate(

# Simulation
@info "Running simulation in the $(backend isa KA.GPU ? "GPU ($gpu_name)" : "CPU with $(sim_params["Nthreads"]) thread(s)")" koma_version =
__VERSION__ sim_method = sim_params["sim_method"] spins = length(obj) time_points = length(
pkgversion(@__MODULE__) sim_method = sim_params["sim_method"] spins = length(obj) time_points = length(
seqd.t
) adc_points = Ndims[1]
@time timed_tuple = @timed run_sim_time_iter!(
Expand Down
5 changes: 4 additions & 1 deletion KomaMRICore/test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
KomaMRICore = "4baa4f4d-2ae9-40db-8331-a7d1080e3f4e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[preferences.KomaMRICore]
test_backend = "CPU"
25 changes: 0 additions & 25 deletions KomaMRICore/test/initialize.jl

This file was deleted.

27 changes: 27 additions & 0 deletions KomaMRICore/test/initialize_backend.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Filtering ARGS (useful for VSCode testing)
AVAILABLE_GPU_BACKENDS = ["CUDA", "AMDGPU", "Metal", "oneAPI"]
TEST_BACKENDS = filter(x->x in [AVAILABLE_GPU_BACKENDS; "CPU"], ARGS)
# Use package preferences if test_args are not specified
if isempty(TEST_BACKENDS)
using Preferences
TEST_BACKENDS = [load_preference(KomaMRICore, "test_backend", "CPU")]
@info "Using [preferences.KomaMRICore]." backend=first(TEST_BACKENDS)
else
@info "Using test_args" backend=first(TEST_BACKENDS)
end
# For testing with CUDA: ] add CUDA to KomaMRICore/test/Project.toml
# For testing with AMDGPU: ] add AMDGPU to KomaMRICore/test/Project.toml
# For testing with Metal: ] add Metal to KomaMRICore/test/Project.toml
# For testing with oneAPI: ] add oneAPI to KomaMRICore/test/Project.toml
USE_GPU = any(AVAILABLE_GPU_BACKENDS .∈ Ref(TEST_BACKENDS))
if "CUDA" in TEST_BACKENDS
using CUDA
elseif "AMDGPU" in TEST_BACKENDS
using AMDGPU
elseif "Metal" in TEST_BACKENDS
using Metal
elseif "oneAPI" in TEST_BACKENDS
using oneAPI
else
@info "CPU using $(Threads.nthreads()) thread(s)" maxlog=1
end
57 changes: 36 additions & 21 deletions KomaMRICore/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
using TestItems, TestItemRunner

### NOTE: by default, tests are run on the CPU with the number of threads set to
# Threads.nthreads(). To run on a specific GPU backend, add the name of the
### NOTE: by default, tests are run on the CPU with the number of threads set to
# Threads.nthreads(). To run on a specific GPU backend, add the name of the
# backend package ("AMDGPU", "CUDA", "Metal", or "oneAPI") to the test/Project.toml
# file in KomaMRICore and pass the name as a test argument.
#
#
# Example:
#
# import Pkg
# Pkg.test("KomaMRICore"; test_args=["CUDA"])
#
# To run on the cpu with a specific number of threads, pass the number of threads
# To run on the cpu with a specific number of threads, pass the number of threads
# as a julia argument.
#
# Example:
#
#
# import Pkg
# Pkg.test("KomaMRICore"; julia_args=`--threads=4`)
#
# For changing the default backend used for testing,
# modify the [preferences.KomaMRICore] section in the test/Project.toml:
#
# [preferences.KomaMRICore]
# test_backend = "CPU"
#
# For the backend preference to take effect, you need to:
# - REPL testing: No action needed. `] test` should pick up the preference right away.
# - VSCode testing: You need to restart VSCode.
#
# Sadly, LocalPreferences.toml are not picked up by VScode (that could be .gitignore'd),
# so we had put them into the test/Project.toml.
#
###

#Environment variable set by CI
Expand Down Expand Up @@ -158,7 +172,7 @@ end
# Test ISMRMRD
@testitem "signal_to_raw_data" tags=[:core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")

seq = PulseDesigner.EPI_example()
sys = Scanner()
Expand Down Expand Up @@ -188,7 +202,7 @@ end

@testitem "Bloch" tags=[:important, :core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")
include(joinpath(@__DIR__, "test_files", "utils.jl"))

sig_jemris = signal_sphere_jemris()
Expand All @@ -211,7 +225,7 @@ end

@testitem "Bloch_RF_accuracy" tags=[:important, :core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")

Tadc = 1e-3
Trf = Tadc
Expand Down Expand Up @@ -258,7 +272,7 @@ end

@testitem "Bloch_phase_compensation" tags=[:important, :core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")

Tadc = 1e-3
Trf = Tadc
Expand Down Expand Up @@ -289,10 +303,10 @@ end

@testitem "Bloch SimpleMotion" tags=[:important, :core, :skipci] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")
include(joinpath(@__DIR__, "test_files", "utils.jl"))

sig_jemris = signal_brain_motion_jemris()
sig_jemris = signal_brain_motion_jemris()
seq = seq_epi_100x100_TE100_FOV230()
sys = Scanner()
obj = phantom_brain_simple_motion()
Expand All @@ -309,10 +323,10 @@ end

@testitem "Bloch ArbitraryMotion" tags=[:important, :core, :skipci] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")
include(joinpath(@__DIR__, "test_files", "utils.jl"))

sig_jemris = signal_brain_motion_jemris()
sig_jemris = signal_brain_motion_jemris()
seq = seq_epi_100x100_TE100_FOV230()
sys = Scanner()
obj = phantom_brain_arbitrary_motion()
Expand All @@ -329,15 +343,15 @@ end

@testitem "BlochDict" tags=[:important, :core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")
include(joinpath(@__DIR__, "test_files", "utils.jl"))

seq = seq_epi_100x100_TE100_FOV230()
obj = Phantom{Float64}(x=[0.], T1=[1000e-3], T2=[100e-3])
sys = Scanner()
sim_params = Dict(
"gpu"=>USE_GPU,
"sim_method"=>KomaMRICore.Bloch(),
"gpu"=>USE_GPU,
"sim_method"=>KomaMRICore.Bloch(),
"return_type"=>"mat")
sig = @suppress simulate(obj, seq, sys; sim_params)
sig = sig / prod(size(obj))
Expand All @@ -353,7 +367,7 @@ end

@testitem "simulate_slice_profile" tags=[:core] begin
using Suppressor
include("initialize.jl")
include("initialize_backend.jl")

# This is a sequence with a sinc RF 30° excitation pulse
sys = Scanner()
Expand All @@ -380,24 +394,25 @@ end
@testitem "GPU Functions" tags=[:core] begin
using Suppressor
import KernelAbstractions as KA
include("initialize.jl")
include("initialize_backend.jl")

x = ones(Float32, 1000)

@suppress begin
y = x |> gpu
if USE_GPU
y = x |> gpu
@test KA.get_backend(y) isa KA.GPU
y = y |> cpu
@test KA.get_backend(y) isa KA.CPU
else
# Test that gpu and cpu are no-ops
y = x |> gpu
@test y == x
y = y |> cpu
@test y == x
end
end


@suppress print_devices()
@test true
end
end
4 changes: 1 addition & 3 deletions KomaMRIFiles/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
MRIFiles = "5a6f062f-bf45-497d-b654-ad17aae2a530"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Scanf = "6ef1bc8b-493b-44e1-8d40-549aa65c4b41"

Expand All @@ -21,10 +20,9 @@ InteractiveUtils = "1"
KomaMRIBase = "0.9"
MAT = "0.10"
MRIFiles = "0.1, 0.2, 0.3"
Pkg = "1.4"
Reexport = "1"
Scanf = "0.5"
julia = "1.9"

[workspace]
projects = ["test"]
projects = ["test"]
4 changes: 0 additions & 4 deletions KomaMRIFiles/src/KomaMRIFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ include("Phantom/Phantom.jl")
export read_seq # Pulseq
export read_phantom_jemris, read_phantom_MRiLab, read_phantom, write_phantom # Phantom

# Package version: KomaMRIFiles.__VERSION__
using Pkg
__VERSION__ = VersionNumber(Pkg.TOML.parsefile(joinpath(@__DIR__, "..", "Project.toml"))["version"])

end # module KomaMRIFiles
4 changes: 2 additions & 2 deletions KomaMRIFiles/src/Phantom/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function import_motion!(
for key in keys(types_group)
type_group = types_group[key]
type_str = split(key, "_")[2]
@assert type_str in last.(split.(string.(subtypes(SimpleMotionType)), ".")) "Simple Motion Type: $(type_str) has not been implemented in KomaMRIBase $(KomaMRIBase.__VERSION__)"
@assert type_str in last.(split.(string.(subtypes(SimpleMotionType)), ".")) "Simple Motion Type: $(type_str) has not been implemented in KomaMRIBase $(pkgversion(KomaMRIBase))"
for SMT in subtypes(SimpleMotionType)
args = []
if type_str == last(split(string(SMT), "."))
Expand Down Expand Up @@ -111,7 +111,7 @@ function write_phantom(
# Create HDF5 phantom file
fid = h5open(filename, "w")
# Root attributes
HDF5.attributes(fid)["Version"] = string(KomaMRIFiles.__VERSION__)
HDF5.attributes(fid)["Version"] = string(pkgversion(KomaMRIFiles))
HDF5.attributes(fid)["Name"] = obj.name
HDF5.attributes(fid)["Ns"] = length(obj.x)
dims = KomaMRIBase.get_dims(obj)
Expand Down
Loading

0 comments on commit c8e76fb

Please sign in to comment.