AlgebraicJulia / Catlab.jl

A framework for applied category theory in the Julia language
https://www.algebraicjulia.org
MIT License
614 stars 58 forks source link

Data migrations with Julia functions on attributes #823

Closed KevinDCarlson closed 1 year ago

KevinDCarlson commented 1 year ago

This PR upgrades the @migration macros with the ability to plug Julia code into appropriate locations. For instance:

The behavior is basically that the macro builds a DataMigration superficially just as it used to, but where some values of the hom_map of the underlying functor may be AttrExpr{:nothing}, and those and perhaps other homs have their values modified upon actually migrated using the Julia functions stored in the migration's params.

The most immediate remaining concern is that the code relies on changes in lots of places, at all three of the key steps of the migration macros (parsing into values from DiagrammaticPrograms.AST, then into actual Diagrams and DiagramHoms, then doing the actual migration), while also allowing for several different syntaxes, and so is not so clean.

The biggest large-scale concern is that we can't yet use multi-input Julia functions, as for instance you'd want to take a product of weighted graphs with the weights of a pair of edges given by the sum of the pair's member's weights. This is an actual semantic step beyond the model we've used so far, as the intermediate migration of something like weight => (x,y) -> weight(x)+weight(y) would need to send Weight to Tuple{Weight,Weight} or to @cases W:Weight; U:Weight, and this splitting would need to be collapsed upon the actual migration. None of this shifting of attribute types happens with examples we can do up till now. The Tuple solution seems easiest, but it does lead to the question of what happens if you have two different combinatorial types using the same attribute type a different number of times each. So I don't think there's an obvious choice of direction here.

KevinDCarlson commented 1 year ago

Ready for re-review (!!!!!)

I should note that there aren't any tests for aggregation and such unintended applications yet.