Skip to content

Collect symbolic struct variables during tearing - #153

Merged
oscardssmith merged 12 commits into
JuliaComputing:mainfrom
Shreyas-Ekanathan:main
Nov 2, 2026
Merged

oscardssmith merged 12 commits into
JuliaComputing:mainfrom
Shreyas-Ekanathan:main

Conversation

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor

Supports future work in MTK to extend symbolic struct features

end
# The fields of a record share a clock: a struct may not be differentially clocked.
# Separate elements of an array of records are separate instances and may differ.
record_group = Dict{SymbolicT, Int}()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An array of records should all have the same clock, right? The same way an array of variables does. @baggepinnen could you please weigh in too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Array elements share the same clock. So an array of structs should do the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This appears to already be the existing behavior, inherited from arrays, so we should be all set here

SymbolicIndexingInterface = "0.3"
SymbolicUtils = "4.25"
Symbolics = "7.20"
Symbolics = "7.23"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this compat bound still correct? Does it include the fixes made to struct support after the initial PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, this bound is what's necessary for this to work

_ => nothing
end
end
# Fields of one record share a clock. Indices are not peeled, so elements of an array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm still confused. Could you explain a bit why this snippet is still necessary? Is there an easy example that hits this case and can be added to a test?

@Shreyas-Ekanathan Shreyas-Ekanathan Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I think I've been doing a poor job here. Currently, the enforcement clocking for arrays as we described is done in SynchToolkit, and I was folding that in here as opposed to in SynchToolkit.

The basic thing we need to enforce is the same thing we've been discussing right, so if I impose a clock on an array, all of the components of the array inherit this single clock. The inheritance happens here, but as I said above, the enforcement of this single clocking happens in SynchToolkit. If this understanding is correct, then I'll just keep the inheritance part.

The split becomes we inherit here (as is done for the elements of a given record) and enforce in SynchToolkit, which appears to be how its done for arrays.

isprojection || continue
j = get!(record_group, root, i)
j == i && continue
add_edge!(inference_graph, (ClockVertex.Variable(i), ClockVertex.Variable(j)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay I think I've managed to wrap my head around this. What this is doing is if we have:

Operator(foo.bar).baz[3].spam
Operator(foo.bar).baz[2].other

It's going to put them on the same clock, which seems fair. What about:

Operator(foo.bar.baz)[3].spam
Operator(foo.bar).baz[2].other

As far as I can tell, these two will also be on the same clock. Is this a sane edge case? Is the behavior what we want it to be? CC @kpamnany

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please expand a bit, for my understanding? What Operator is this, for example?

If a component has two different instances, then those should not be put on the same clock.

@AayushSabharwal AayushSabharwal Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just any general clock operator. Here the variable is foo, in a flat model for simplicity (no hierarchical components)

@variables foo(t)::SomeRecordType

I'm not sure if there are cases where ST would put clock operators on non-leaf fields of structs, and what the semantics of those would be. If some operator Op has different output and input clocks, are the following two cases equivalent, or even valid?

Op(foo.bar.baz)[3].spam
Op(foo.bar).baz[3].spam

If they're valid, are they on the same clock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not convinced that this example is valid? Why is it guaranteed or expected that the output of Op(foo.bar) will have a field baz?

More generally, this is an extension of single clocking of a record, to single clock all records in a given array (by adding the edges as shown above).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the contents of foo should be on the same clock. I cannot, at the moment, think of a clock domain crossing operator that could confuse this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay sure, then I guess this PR looks okay.

@oscardssmith
oscardssmith merged commit 8e7ce91 into JuliaComputing:main Nov 2, 2026
8 of 9 checks passed
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.

4 participants