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

Sermon et al. helper functions #378

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Sermon et al. helper functions #378

wants to merge 10 commits into from

Conversation

agchesebro
Copy link
Member

Helper functions to resolve #377.

@agchesebro
Copy link
Member Author

@harisorgn the latest version of sermon_dbs_tutorial.jl has the different weights I'd mentioned. The comments on lines 40-51 are the initial version where I was building the connection rule into the weight and then just letting it get multiplied by the rest of the expression in BloxConnector. The one in lines 53-60 is the one that actually can go through structural_simplify without errors because I moved all of the things into kwargs to avoid the states getting collected as parameters. The dispatch of BloxConnector for this rule is in sermon_dbs.jl starting at line 72. For reference, these equations come from the Sermon paper equations 1, 5, and 6.

@agchesebro
Copy link
Member Author

@helmutstrey @harisorgn quick update: I've got the code working in the sense that it's all connected and running, but it doesn't remotely reproduce the paper with the parameters and equations the authors give. I've noted some diagnostic plots that should reproduce some of the figures from the paper directly (but don't) and where I think there must be a dropped factor in one of the equations. I'll also put this in Slack so we can discuss if it's worth reaching out to the authors for their code.


if haskey(kwargs, :sermon_rule)
if haskey(kwargs, :extra_bloxs) && haskey(kwargs, :extra_params)
RRP, RP, RtP = kwargs[:extra_bloxs]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks hardcoded for the particular tutorial case, i.e. expecting 3 elements in kwargs[:extra_bloxs]. You can imagine this breaking very easily if a user passes a different number in that keyword. We should generalize this in a loop, seems doable?

out_RP = namespace_expr(RP.output, get_namespaced_sys(RP))
out_RtP = namespace_expr(RtP.output, get_namespaced_sys(RtP))

M_RRP, M_RP, M_RtP, k_μ, I = kwargs[:extra_params]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above about kwargs[:extra_bloxs] but now it's kwargs[:extra_params]. I understand that we might want to keep this conenction rule specific to the tutorial (for now) in the interest of development speed, but we should think about the most likely breaking cases.

w = generate_weight_param(bloxout, bloxin; kwargs...)
push!(bc.weights, w)

if haskey(kwargs, :sermon_rule)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an else to this if. Could we just claim that (for now) :sermon_rule is the only possible connection rule to reduce the kwargs that are exposed to the user? Or were you planning on adding more rules?

@harisorgn
Copy link
Member

Does it make sense to define a PooledKuramotoOscillator <: CompositeBlox that contains some pools and some oscillators? The oscillators would then connect to each other based on pool parameters as you want, and the System that is contained in this new Blox would hold all pool parameters and states, so you don't get any complaints on the final system construction/simplification. I think something like this would work and it's not too hard to get namespaces correctly.

The alternative could be that you keep pools and oscillators separate as you do and pass in the connection rule between oscillators some expression that involves pool states/parameters. We would then need to get the namespaces of these pool symbolics correct, so that you don't get almost duplicates in structural_simplify (e.g. pool1.state1 and global_namespace.pool1.state1) which I suspect is an issue with your original implementation.

# Create a new DBS stimulator block
# Largely based on MTK Standard Library pulse block from the digital electronics
# Implements unnumbered equation below equation 2 for the pulse train, with default parameters from the paper
struct SermonDBS <: NeuralMassBlox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrevaya this is the stimulator for an arbitrary pulse train

end

# Connects the DBS stimulator to the Kuramoto oscillators (Iₜ term in equation 1)
function (bc::BloxConnector)(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrevaya this is the connection rule for the DBS stimulator to Kuramoto blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helper blocks for Sermon et al. example need implementing
2 participants