From 02f8d2d4d2300a577317e725c4191593d7b82c7b Mon Sep 17 00:00:00 2001
From: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
Date: Mon, 12 Feb 2024 14:11:14 +0000
Subject: [PATCH] add make_generic on MRI sequence components

---
 src/components/instant_gradients.jl        |  3 ++-
 src/components/pulses/constant_pulses.jl   |  2 +-
 src/components/pulses/generic_pulses.jl    |  2 +-
 src/components/pulses/instant_pulses.jl    |  2 +-
 src/components/pulses/sinc_pulses.jl       |  2 +-
 src/components/readouts/ADCs.jl            |  2 +-
 src/components/readouts/single_readouts.jl |  2 +-
 src/variables.jl                           | 13 +++++++++++++
 8 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/components/instant_gradients.jl b/src/components/instant_gradients.jl
index 08e9cc9..cc2801c 100644
--- a/src/components/instant_gradients.jl
+++ b/src/components/instant_gradients.jl
@@ -1,6 +1,6 @@
 module InstantGradients
 import StaticArrays: SVector, SMatrix
-import ...Variables: VariableType, duration, qvec, bmat_gradient, get_free_variable, set_simple_constraints!, qval, effective_time
+import ...Variables: VariableType, duration, qvec, bmat_gradient, get_free_variable, set_simple_constraints!, qval, effective_time, make_generic
 import ..AbstractTypes: EventComponent, GradientWaveform
 
 """
@@ -78,5 +78,6 @@ duration(::InstantGradient) = 0.
 effective_time(::InstantGradient) = 0.
 bmat_gradient(::InstantGradient, qstart=nothing) = zero(SMatrix{3, 3, Float64, 3})
 
+make_generic(ig::InstantGradient) = ig
 
 end
\ No newline at end of file
diff --git a/src/components/pulses/constant_pulses.jl b/src/components/pulses/constant_pulses.jl
index 7cb42e6..f240dac 100644
--- a/src/components/pulses/constant_pulses.jl
+++ b/src/components/pulses/constant_pulses.jl
@@ -2,7 +2,7 @@ module ConstantPulses
 import JuMP: @constraint
 import ...AbstractTypes: RFPulseComponent
 import ....BuildSequences: global_model
-import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType, set_simple_constraints!, frequency
+import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType, set_simple_constraints!, frequency, make_generic
 import ..GenericPulses: GenericPulse
 
 """
diff --git a/src/components/pulses/generic_pulses.jl b/src/components/pulses/generic_pulses.jl
index 08ac34d..a21af01 100644
--- a/src/components/pulses/generic_pulses.jl
+++ b/src/components/pulses/generic_pulses.jl
@@ -1,7 +1,7 @@
 module GenericPulses
 
 import ...AbstractTypes: RFPulseComponent
-import ....Variables: duration, amplitude, effective_time, flip_angle
+import ....Variables: duration, amplitude, effective_time, flip_angle, make_generic
 
 
 """
diff --git a/src/components/pulses/instant_pulses.jl b/src/components/pulses/instant_pulses.jl
index 826c6db..d473299 100644
--- a/src/components/pulses/instant_pulses.jl
+++ b/src/components/pulses/instant_pulses.jl
@@ -2,7 +2,7 @@ module InstantPulses
 import JuMP: @constraint
 import ...AbstractTypes: RFPulseComponent
 import ....BuildSequences: global_model
-import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType
+import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType, make_generic
 
 """
     InstantPulse(; flip_angle=nothing, phase=nothing, group=nothing)
diff --git a/src/components/pulses/sinc_pulses.jl b/src/components/pulses/sinc_pulses.jl
index 3511399..8e19aa3 100644
--- a/src/components/pulses/sinc_pulses.jl
+++ b/src/components/pulses/sinc_pulses.jl
@@ -2,7 +2,7 @@ module SincPulses
 import JuMP: @constraint
 import QuadGK: quadgk
 import ....BuildSequences: global_model
-import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType, set_simple_constraints!, frequency
+import ....Variables: duration, amplitude, effective_time, flip_angle, phase, inverse_bandwidth, VariableType, set_simple_constraints!, frequency, make_generic
 import ...AbstractTypes: RFPulseComponent
 import ..GenericPulses: GenericPulse
 
diff --git a/src/components/readouts/ADCs.jl b/src/components/readouts/ADCs.jl
index a592406..20db487 100644
--- a/src/components/readouts/ADCs.jl
+++ b/src/components/readouts/ADCs.jl
@@ -1,6 +1,6 @@
 module ADCs
 import JuMP: @constraint, value
-import ...Variables: variables, dwell_time, duration, effective_time, get_free_variable, VariableType, nsamples, resolution, oversample
+import ...Variables: variables, dwell_time, duration, effective_time, get_free_variable, VariableType, nsamples, resolution, oversample, make_generic
 import ...BuildingBlocks: BuildingBlock, apply_simple_constraint!, set_simple_constraints!, fixed, make_generic
 import ...BuildSequences: global_model
 
diff --git a/src/components/readouts/single_readouts.jl b/src/components/readouts/single_readouts.jl
index 1ec879f..ee97eed 100644
--- a/src/components/readouts/single_readouts.jl
+++ b/src/components/readouts/single_readouts.jl
@@ -1,6 +1,6 @@
 module InstantReadouts
 import ...AbstractTypes: ReadoutComponent
-import ...Variables: variables, duration, effective_time
+import ...Variables: variables, duration, effective_time, make_generic
 import ..ADCs: ADC
 
 """
diff --git a/src/variables.jl b/src/variables.jl
index ac091cb..1101fd0 100644
--- a/src/variables.jl
+++ b/src/variables.jl
@@ -252,4 +252,17 @@ apply_simple_constraint!(variable, value::VariableType) = @constraint global_mod
 apply_simple_constraint!(variable::AbstractVector, value::AbstractVector) = [apply_simple_constraint!(v1, v2) for (v1, v2) in zip(variable, value)]
 apply_simple_constraint!(variable::Number, value::Number) = @assert variable ≈ value "Variable set to multiple incompatible values."
 
+
+"""
+    make_generic(sequence/building_block/component)
+
+Returns a generic version of the `BaseSequence`, `BaseBuildingBlock`, or `BaseComponent`
+
+- Sequences are all flattened and returned as a single `Sequence` containing only `BuildingBlock` objects.
+- Any `BaseBuildingBlock` is converted into a `BuildingBlock`.
+- Pulses are replaced with `GenericPulse` (except for instant pulses).
+- Instant readouts are replaced with `ADC`.
+"""
+function make_generic end
+
 end
\ No newline at end of file
-- 
GitLab