Skip to content
Snippets Groups Projects
Verified Commit 11d11853 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Rename properties to variables

parent c933e61e
No related branches found
No related tags found
No related merge requests found
...@@ -8,8 +8,8 @@ Parent type for all individual components out of which a sequence can be built. ...@@ -8,8 +8,8 @@ Parent type for all individual components out of which a sequence can be built.
Required methods: Required methods:
- [`duration`](@ref)(block, parameters): returns block duration in ms. - [`duration`](@ref)(block, parameters): returns block duration in ms.
- [`to_concrete_block`](@ref)(builder, block): converts the block into a `ConcreteBlock`, which will be part of given `SequenceBuilder`. - [`to_concrete_block`](@ref)(sequence, block): converts the block into a `ConcreteBlock`, which will be part of given `Sequence`.
- [`properties`](@ref): A list of all functions that are used to compute properties of the building block. Any of these can be used in constraints or objective functions. - [`variables`](@ref): A list of all functions that are used to compute variables of the building block. Any of these can be used in constraints or objective functions.
""" """
abstract type BuildingBlock end abstract type BuildingBlock end
...@@ -52,18 +52,18 @@ end ...@@ -52,18 +52,18 @@ end
function scanner_constraints!(model::Model, building_block::BuildingBlock, scanner::Scanner) function scanner_constraints!(model::Model, building_block::BuildingBlock, scanner::Scanner)
for func in [gradient_strength, slew_rate] for func in [gradient_strength, slew_rate]
if (func in properties(building_block)) && isfinite(func(scanner)) if (func in variables(building_block)) && isfinite(func(scanner))
@constraint model func(building_block) <= func(scanner) @constraint model func(building_block) <= func(scanner)
end end
end end
end end
""" """
properties(building_block) variables(building_block)
Returns a list of function that can be called to constrain the `building_block`. Returns a list of function that can be called to constrain the `building_block`.
""" """
properties(bb::BuildingBlock) = properties(typeof(bb)) variables(bb::BuildingBlock) = variables(typeof(bb))
struct _BuildingBlockPrinter struct _BuildingBlockPrinter
bb :: BuildingBlock bb :: BuildingBlock
...@@ -85,14 +85,14 @@ function Base.show(io::IO, block::BuildingBlock) ...@@ -85,14 +85,14 @@ function Base.show(io::IO, block::BuildingBlock)
end end
for name in propertynames(block) for name in propertynames(block)
value = getproperty(block, name) value = getproperty(block, name)
if value isa GenericVariableRef || name == :builder || string(name)[1] == '_' if value isa GenericVariableRef || name == :parent || string(name)[1] == '_'
continue continue
end end
print(io, name, "=", repr(value), ", ") print(io, name, "=", repr(value), ", ")
end end
if has_values(block) if has_values(block)
for fn in properties(block) for fn in variables(block)
if fn == duration if fn == duration
continue continue
end end
...@@ -112,14 +112,14 @@ function end_time end ...@@ -112,14 +112,14 @@ function end_time end
""" """
set_simple_constraints!(model, block, kwargs) set_simple_constraints!(model, block, kwargs)
Add any constraints or objective functions to the properties of a [`BuildingBlock`](@ref) in the JuMP `model`. Add any constraints or objective functions to the variables of a [`BuildingBlock`](@ref) in the JuMP `model`.
Each keyword argument has to match one of the functions in [`properties`](@ref)(block). Each keyword argument has to match one of the functions in [`variables`](@ref)(block).
If set to a numeric value, a constraint will be added to fix the function value to that numeric value. If set to a numeric value, a constraint will be added to fix the function value to that numeric value.
If set to `:min` or `:max`, minimising or maximising this function will be added to the cost function. If set to `:min` or `:max`, minimising or maximising this function will be added to the cost function.
""" """
function set_simple_constraints!(model::Model, block::BuildingBlock, kwargs) function set_simple_constraints!(model::Model, block::BuildingBlock, kwargs)
to_funcs = Dict(nameof(fn) => fn for fn in properties(block)) to_funcs = Dict(nameof(fn) => fn for fn in variables(block))
for (key, value) in kwargs for (key, value) in kwargs
apply_simple_constraint!(model, to_funcs[key](block), value) apply_simple_constraint!(model, to_funcs[key](block), value)
end end
...@@ -142,8 +142,8 @@ apply_simple_constraint!(model::Model, variable, value::Number) = @constraint mo ...@@ -142,8 +142,8 @@ apply_simple_constraint!(model::Model, variable, value::Number) = @constraint mo
""" """
match_blocks!(block1, block2[, property_list]) match_blocks!(block1, block2[, property_list])
Matches the listed properties between two [`BuildingBlock`](@ref) objects. Matches the listed variables between two [`BuildingBlock`](@ref) objects.
By default all shared properties (i.e., those with the same name) are matched. By default all shared variables (i.e., those with the same name) are matched.
""" """
function match_blocks!(block1::BuildingBlock, block2::BuildingBlock, property_list) function match_blocks!(block1::BuildingBlock, block2::BuildingBlock, property_list)
model = owner_model(block1) model = owner_model(block1)
...@@ -154,7 +154,7 @@ function match_blocks!(block1::BuildingBlock, block2::BuildingBlock, property_li ...@@ -154,7 +154,7 @@ function match_blocks!(block1::BuildingBlock, block2::BuildingBlock, property_li
end end
function match_blocks!(block1::BuildingBlock, block2::BuildingBlock) function match_blocks!(block1::BuildingBlock, block2::BuildingBlock)
property_list = intersect(properties(block1), properties(block2)) property_list = intersect(variables(block1), variables(block2))
match_blocks!(block1, block2, property_list) match_blocks!(block1, block2, property_list)
end end
......
...@@ -117,7 +117,7 @@ function to_concrete_block(sequence::AbstractSequence, cb::ConcreteBlock) ...@@ -117,7 +117,7 @@ function to_concrete_block(sequence::AbstractSequence, cb::ConcreteBlock)
return ConcreteBlock(sequence, cb.duration, cb.pulse, cb.gradient, cb.readout_times) return ConcreteBlock(sequence, cb.duration, cb.pulse, cb.gradient, cb.readout_times)
end end
properties(::Type{<:AbstractConcreteBlock}) = [] variables(::Type{<:AbstractConcreteBlock}) = []
""" """
......
...@@ -41,7 +41,7 @@ end ...@@ -41,7 +41,7 @@ end
qval(instant::InstantGradientBlock) = instant.qval qval(instant::InstantGradientBlock) = instant.qval
bval(instant::InstantGradientBlock) = 0. bval(instant::InstantGradientBlock) = 0.
duration(instant::InstantGradientBlock) = 0. duration(instant::InstantGradientBlock) = 0.
properties(::Type{<:InstantGradientBlock}) = [qval] variables(::Type{<:InstantGradientBlock}) = [qval]
""" """
ConcreteInstantGradient(orientation, qval) ConcreteInstantGradient(orientation, qval)
......
...@@ -113,7 +113,7 @@ function bval(g::PulsedGradient, qstart=0.) ...@@ -113,7 +113,7 @@ function bval(g::PulsedGradient, qstart=0.)
) )
end end
properties(::Type{<:PulsedGradient}) = [qval, δ, gradient_strength, duration, rise_time, flat_time, slew_rate] variables(::Type{<:PulsedGradient}) = [qval, δ, gradient_strength, duration, rise_time, flat_time, slew_rate]
function to_concrete_block(s::AbstractSequence, block::PulsedGradient) function to_concrete_block(s::AbstractSequence, block::PulsedGradient)
......
...@@ -47,7 +47,7 @@ frequency(pulse::ConstantPulse) = pulse.frequency ...@@ -47,7 +47,7 @@ frequency(pulse::ConstantPulse) = pulse.frequency
flip_angle(pulse::ConstantPulse) = amplitude(pulse) * duration(pulse) * 360 flip_angle(pulse::ConstantPulse) = amplitude(pulse) * duration(pulse) * 360
bandwidth(pulse::ConstantPulse) = 3.79098854 / duration(pulse) bandwidth(pulse::ConstantPulse) = 3.79098854 / duration(pulse)
properties(::Type{<:ConstantPulse}) = [amplitude, duration, phase, frequency, flip_angle, bandwidth] variables(::Type{<:ConstantPulse}) = [amplitude, duration, phase, frequency, flip_angle, bandwidth]
function to_concrete_block(s::AbstractSequence, block::ConstantPulse) function to_concrete_block(s::AbstractSequence, block::ConstantPulse)
d = value(duration(block)) d = value(duration(block))
......
...@@ -27,7 +27,7 @@ end ...@@ -27,7 +27,7 @@ end
flip_angle(instant::InstantRFPulseBlock) = instant.flip_angle flip_angle(instant::InstantRFPulseBlock) = instant.flip_angle
phase(instant::InstantRFPulseBlock) = instant.phase phase(instant::InstantRFPulseBlock) = instant.phase
duration(instant::InstantRFPulseBlock) = 0. duration(instant::InstantRFPulseBlock) = 0.
properties(::Type{<:InstantRFPulseBlock}) = [flip_angle, phase] variables(::Type{<:InstantRFPulseBlock}) = [flip_angle, phase]
""" """
......
...@@ -98,7 +98,7 @@ frequency(pulse::SincPulse) = pulse.frequency ...@@ -98,7 +98,7 @@ frequency(pulse::SincPulse) = pulse.frequency
flip_angle(pulse::SincPulse) = (pulse.nlobe_integral(N_left(pulse)) + pulse.nlobe_integral(N_right(pulse))) * amplitude(pulse) * lobe_duration(pulse) * 360 flip_angle(pulse::SincPulse) = (pulse.nlobe_integral(N_left(pulse)) + pulse.nlobe_integral(N_right(pulse))) * amplitude(pulse) * lobe_duration(pulse) * 360
lobe_duration(pulse::SincPulse) = pulse.lobe_duration lobe_duration(pulse::SincPulse) = pulse.lobe_duration
bandwidth(pulse::SincPulse) = 1 / lobe_duration(pulse) bandwidth(pulse::SincPulse) = 1 / lobe_duration(pulse)
properties(::Type{<:SincPulse}) = [amplitude, N_left, N_right, duration, phase, frequency, flip_angle, lobe_duration, bandwidth] variables(::Type{<:SincPulse}) = [amplitude, N_left, N_right, duration, phase, frequency, flip_angle, lobe_duration, bandwidth]
function to_concrete_block(s::AbstractSequence, block::SincPulse) function to_concrete_block(s::AbstractSequence, block::SincPulse)
normed_times = -value(N_left(block)):0.1:value(N_right(block)) + 1e-5 normed_times = -value(N_left(block)):0.1:value(N_right(block)) + 1e-5
......
...@@ -16,7 +16,7 @@ end ...@@ -16,7 +16,7 @@ end
InstantReadout() = BuildingBlockPlaceholder{InstantReadout}() InstantReadout() = BuildingBlockPlaceholder{InstantReadout}()
properties(::Type{<:InstantReadout}) = [] variables(::Type{<:InstantReadout}) = []
to_block(builder::SequenceBuilder, cls::Type{<:InstantReadout}) = cls(builder) to_block(builder::SequenceBuilder, cls::Type{<:InstantReadout}) = cls(builder)
to_concrete_block(builder::AbstractSequence, ::InstantReadout) = InstantReadout(builder) to_concrete_block(builder::AbstractSequence, ::InstantReadout) = InstantReadout(builder)
......
...@@ -36,7 +36,7 @@ WaitBlock(duration_constraint=nothing) = BuildingBlockPlaceholder{WaitBlock}(dur ...@@ -36,7 +36,7 @@ WaitBlock(duration_constraint=nothing) = BuildingBlockPlaceholder{WaitBlock}(dur
to_block(builder::SequenceBuilder, time::Union{Number, Symbol, Nothing, Val{:min}, Val{:max}}) = WaitBlock(builder, time) to_block(builder::SequenceBuilder, time::Union{Number, Symbol, Nothing, Val{:min}, Val{:max}}) = WaitBlock(builder, time)
properties(::Type{WaitBlock}) = [duration] variables(::Type{WaitBlock}) = [duration]
duration(wb::WaitBlock) = wb.duration duration(wb::WaitBlock) = wb.duration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment