AlgebraicJulia / AlgebraicJulia/Catlab.jl

Ocompose for UWD with renaming of junction labels

未关闭
#574 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Julia
星标
724
派生
73
PR 合并指标
30 天内没有已合并 PR

描述

@epatters, @bosonbaas, this snippet does the composition of UWDs with renaming of the variables via the outer ports like we discussed for the composition of equations. I've tested it on some UWDs, but before I make a PR with tests and stuff. We have some bikeshedding.

1. Where should this live? If this we are using Structured Cospans of Equations beyond just physics, we should probably put it in Catlab with the UWDs directly
2. Is this a new function ocompose_rename or can we specialize on UWDs with names and make this ocompose the default for that operad? The current version of ocompose for `UntypedUnnamedRelationDiagram` checks that the names match, which is really useless because you have to globally name things coherently before you start composing.
3. I wrote this by mutating the variable column on the input subsystems. None of our ocomposes are destructive on their arguments so far. So this code should probably by fused into the current ocompose implementation to avoid doing a copy of the arguments before composing.
4. How strictly do we want to make the type parameters on this?

```julia
function rename_variables!(uwd, boxes)
map(1:length(boxes)) do b
ports = incident(uwd, b, :box)
jnames = uwd[ports, [:junction, :variable]]
newnames = map(parts(boxes[b], :OuterPort)) do op
j = boxes[b][op, :outer_junction]
oldname = boxes[b][j, :variable]
# for box $b outer junction $j, renames $oldname → $(jnames[j])
return jnames[j]
end
boxes[b][boxes[b][:outer_junction], :variable] .= newnames
end
return boxes
end
ocompose_rename!(uwd, boxes) = ocompose(uwd, rename_variables!(uwd,boxes))
```

@slibkind, would this help satisfy the need for LACSets in AlgebraicDynamics? It is an ocompose for UWDs where the junctions have names and when you ocompose, you take the names from the outer diagram and assign them to the junctions of the inner diagram.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。