Skip to content
Open
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ MPIRecoDaggerExt = ["Dagger", "DaggerImageReconstruction"]
MPIRecoKernelAbstractionsExt = ["Atomix", "KernelAbstractions", "GPUArrays"]

[compat]
AbstractImageReconstruction = "0.5"
AbstractImageReconstruction = "0.6"
Adapt = "3, 4"
Atomix = "1"
DSP = "0.6, 0.7, 0.8"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate/howtos/custom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ b = MPIFile(joinpath(datadir, "measurements", "20211226_203916_MultiPatch", "1.m
# ## Custom Processing Steps
# To implement a custom processing step, we need to add a new parameter struct, in our case we want to extend `AbstractWeightingParameters`.
# As a toy-example, we will implement a weighting strategy in which frequencies are weighting with an alternating sequence of weights:
Base.@kwdef struct AlternatingWeightingParameters <: AbstractWeightingParameters
@parameter struct AlternatingWeightingParameters <: AbstractWeightingParameters
alternatingWeights::Vector{Float64}
end
# The `Base.@kwdef` macro generates a keyword-argment constructor with optional default values. Next, we can implement the actual processing function.
# The `@parameter` macro generates a keyword-argment constructor with optional default values. Next, we can implement the actual processing function.

# Different algorithms can have different implementations of a given weighting strategy and we can specialise a function on the type of algorithm or an algorithm instance itself.
# The former is helpful for pure functions, i.e. processing steps which solely depend on the given parameter and processing-arguments, not the state of the algorithm.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/literate/howtos/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module CustomWeighting
using MPIReco.AbstractImageReconstruction

export AlternatingWeightingParameters
Base.@kwdef struct AlternatingWeightingParameters <: AbstractWeightingParameters
@parameter struct AlternatingWeightingParameters <: AbstractWeightingParameters
alternatingWeights::Vector{Float64}
end

Expand Down
2 changes: 1 addition & 1 deletion docs/src/literate/howtos/solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ hidedecorations!(fig.axis)
fig

# If our custom solver requires custom parameters, we could implement custom solver parameters in MPIReco:
Base.@kwdef struct OurSolverParameters <: MPIReco.AbstractSolverParameters{OurSolver}
@parameter struct OurSolverParameters <: MPIReco.AbstractSolverParameters{OurSolver}
notification::String
enforceReal::Bool=true
enforcePositive::Bool=true
Expand Down
4 changes: 2 additions & 2 deletions ext/MPIRecoKernelAbstractionsExt/Weighting.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function AbstractImageReconstruction.process(algo::Type{<:AbstractMPIRecoAlgorithm}, params::ProcessResultCache{<:AbstractWeightingParameters}, freqs, S, meas, arrType::Type{<:AbstractGPUArray})
function (params::ProcessResultCache{<:AbstractWeightingParameters})(algo::Type{<:AbstractMPIRecoAlgorithm}, freqs, S, meas, arrType::Type{<:AbstractGPUArray})
@warn "Caching of weight processing is disabled for GPU processing"
return process(algo, params.param, freqs, S, meas, arrType)
return params.param(algo, freqs, S, meas, arrType)
end
7 changes: 5 additions & 2 deletions src/AlgorithmInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract type AbstractMPIPreProcessingParameters{T<:AbstractMPIBackgroundCorrect
export AbstractMPIPostProcessingParameters, NoPostProcessing
abstract type AbstractMPIPostProcessingParameters <: AbstractMPIRecoParameters end
struct NoPostProcessing <: AbstractMPIPostProcessingParameters end # TODO remove later
process(algo::AbstractMPIRecoAlgorithm, ::NoPostProcessing, data) = data
(::NoPostProcessing)(algo::AbstractMPIRecoAlgorithm, data) = data

export AbstractMPIReconstructionParameters
abstract type AbstractMPIReconstructionParameters <: AbstractMPIRecoParameters end
Expand All @@ -42,6 +42,9 @@ struct MixedAlgorithm <: ReconstructionAlgorithmType end
# TODO recoAlgorithmType
# TODO undefined for certain "Algorithm" components
#recoAlgorithmTypes(::Type{ConcreteRecoAlgorithm}) = SystemMatrixBasedAlgorithm()
export MPIRecoStyle
struct MPIRecoStyle <: CustomPlanStyle end

export addRecoPlanPath, getRecoPlanList
const DEFAULT_PLANS_PATH = @path joinpath(@__DIR__, "..", "config")
const recoPlanPaths = AbstractString[DEFAULT_PLANS_PATH]
Expand Down Expand Up @@ -170,7 +173,7 @@ function loadRecoPlan(planfile::AbstractString, modules; kwargs...)
end
# Load plan from an io (could be file or iobuffer backed string)
function loadRecoPlan(io, modules; kwargs...)
plan = loadPlan(io, modules)
plan = loadPlan(io, modules; field_style = MPIRecoStyle())
setKwargs!(plan; kwargs...)
return plan
end
Expand Down
4 changes: 2 additions & 2 deletions src/Algorithms/HandsFreeAlgorithms/HandsFreeLeastSquares.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export HandsFreeSolverParameters
Base.@kwdef struct HandsFreeSolverParameters <: AbstractSolverParameters{Kaczmarz}
@parameter struct HandsFreeSolverParameters <: AbstractSolverParameters{Kaczmarz}
iterbounds::Tuple{Int64, Int64}=(1, 25)
enforceReal::Bool=true
enforcePositive::Bool=true
Expand All @@ -11,7 +11,7 @@ Base.@kwdef struct HandsFreeSolverParameters <: AbstractSolverParameters{Kaczmar
flattenIters::Bool=false
end

function process(t::Type{<:AbstractMPIRecoAlgorithm}, params::LeastSquaresParameters{Kaczmarz, O, SF, R, SL, W}, u::AbstractArray, snr::AbstractVector) where {O, SF, R, SL <: HandsFreeSolverParameters, W}
function (params::LeastSquaresParameters{Kaczmarz, O, SF, R, SL, W})(t::Type{<:AbstractMPIRecoAlgorithm}, u::AbstractArray, snr::AbstractVector) where {O, SF, R, SL <: HandsFreeSolverParameters, W}

solverParams = params.solverParams
N = size(params.S, 2)
Expand Down
14 changes: 7 additions & 7 deletions src/Algorithms/HandsFreeAlgorithms/HandsFreeSinglePatch.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export SinglePatchHandsFreeReconstructionParameter
Base.@kwdef struct SinglePatchHandsFreeReconstructionParameter{L<:AbstractSystemMatrixLoadingParameter,
@parameter struct SinglePatchHandsFreeReconstructionParameter{L<:AbstractSystemMatrixLoadingParameter,
arrT <: AbstractArray, SP<:HandsFreeSolverParameters, W<:AbstractWeightingParameters} <: AbstractSinglePatchReconstructionParameters
# File
sf::MPIFile
Expand All @@ -12,24 +12,24 @@ Base.@kwdef struct SinglePatchHandsFreeReconstructionParameter{L<:AbstractSystem
end

function prepareSystemMatrix(reco::SinglePatchHandsFreeReconstructionParameter{L}) where {L<:AbstractSystemMatrixLoadingParameter}
freqs, sf, grid = process(AbstractMPIRecoAlgorithm, reco.sfLoad, reco.sf, Kaczmarz, reco.arrayType)
freqs, sf, grid = reco.sfLoad(AbstractMPIRecoAlgorithm, reco.sf, Kaczmarz, reco.arrayType)
return freqs, sf, grid, reco.arrayType
end

function prepareWeights(reco::SinglePatchHandsFreeReconstructionParameter{L,arrT,SP,W}, freqs, sf) where {L, arrT, SP, W<:AbstractWeightingParameters}
return process(AbstractMPIRecoAlgorithm, reco.weightingParams, freqs, sf, nothing, reco.arrayType)
return reco.weightingParams(AbstractMPIRecoAlgorithm, reco.weightingParams, freqs, sf, nothing, reco.arrayType)
end

function process(algo::SinglePatchReconstructionAlgorithm, params::SinglePatchHandsFreeReconstructionParameter, u)
weights = process(algo, params.weightingParams, u, WeightingType(params.weightingParams))
function (params::SinglePatchHandsFreeReconstructionParameter)(algo::SinglePatchReconstructionAlgorithm, u)
weights = params.weightingParams(algo, u, WeightingType(params.weightingParams))

B = getLinearOperator(algo, params)

solver = LeastSquaresParameters(op = B, S = algo.S, reg = L2Regularization[], solverParams = params.solverParams, weights = weights)

snr = real(eltype(algo.S)).(vec(MPIFiles.getCalibSNR(algo.sf)[algo.freqs, 1]))

result = process(algo, solver, u, snr)
result = solver(algo, u, snr)

return gridresult(result, algo.grid, algo.sf)
end
Expand All @@ -39,5 +39,5 @@ function getLinearOperator(algo::SinglePatchReconstructionAlgorithm, params::Sin
end

function getLinearOperator(algo::SinglePatchReconstructionAlgorithm, params::SinglePatchHandsFreeReconstructionParameter{<:SparseSystemMatrixLoadingParameter})
return process(algo, params.sfLoad, eltype(algo.S), algo.arrayType, tuple(shape(algo.grid)...))
return params.sfLoad(algo, eltype(algo.S), algo.arrayType, tuple(shape(algo.grid)...))
end
18 changes: 3 additions & 15 deletions src/Algorithms/LowLevelAlgorithm.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
export LowLevelReconstructionAlgorithm
Base.@kwdef struct LowLevelReconstructionAlgorithm{P <: LeastSquaresParameters} <: AbstractMPIRecoAlgorithm
params::P
output::Channel{Any}
LowLevelReconstructionAlgorithm(params::P) where P = new{P}(params, Channel{Any}(Inf))
end
recoAlgorithmTypes(::Type{LowLevelReconstructionAlgorithm}) = SystemMatrixBasedAlgorithm()
AbstractImageReconstruction.parameter(algo::LowLevelReconstructionAlgorithm) = algo.params
Base.lock(algo::LowLevelReconstructionAlgorithm) = lock(algo.output)
Base.unlock(algo::LowLevelReconstructionAlgorithm) = unlock(algo.output)
Base.isready(algo::LowLevelReconstructionAlgorithm) = isready(algo.output)
Base.wait(algo::LowLevelReconstructionAlgorithm) = wait(algo.output)
AbstractImageReconstruction.take!(algo::LowLevelReconstructionAlgorithm) = Base.take!(algo.output)

function AbstractImageReconstruction.put!(algo::LowLevelReconstructionAlgorithm, u::AbstractArray)
put!(algo.output, process(algo, algo.params, u))
@reconstruction struct LowLevelReconstructionAlgorithm{P <: LeastSquaresParameters} <: AbstractMPIRecoAlgorithm
@parameter params::P
end
recoAlgorithmTypes(::Type{LowLevelReconstructionAlgorithm}) = SystemMatrixBasedAlgorithm()
Loading
Loading