Skip to content

Add StyledHook + graph-level terminate!#226

Merged
gpeairs merged 7 commits into
mainfrom
gp/self-termination
May 28, 2026
Merged

Add StyledHook + graph-level terminate!#226
gpeairs merged 7 commits into
mainfrom
gp/self-termination

Conversation

@gpeairs

@gpeairs gpeairs commented May 21, 2026

Copy link
Copy Markdown
Member

Adds a StyledHook{T, H<:Hook{T}, S} <: Hook{T} wrapper that augments any Hook with a carried path-style object, plus graph-level terminate! methods that use the carried style (or an explicit style= kwarg) to attach a termination cap to a schematic node's hook. Exports StyledHook and hook_style at the top level.

Path and RouteComponent hooks are now StyledHooks carrying the style at the start or end of the path. For p1 hooks, this is just nextstyle (or nothing for empty paths). For p0 hooks, this is computed as nextstyle on the reversal of the initial node (or nothing for empty paths), so this PR also implements reverse for Path styles that still needed it.

Also contains the same fix for RouteComponent p1 hook direction as in #213.

StyledHook can be used to verify style agreement for fused components, and terminate! can be useful in constructing truncated models for simulation.

@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.10145% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/paths/contstyles/strands.jl 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@gpeairs gpeairs force-pushed the gp/self-termination branch 2 times, most recently from 8d79c83 to 327263d Compare May 21, 2026 11:55
@gpeairs gpeairs requested a review from simlapointe May 21, 2026 12:01
@gpeairs gpeairs force-pushed the gp/self-termination branch from 327263d to ce37a1f Compare May 21, 2026 13:05

@simlapointe simlapointe left a comment

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.

Overall looks good to me. Two comments below; one of them might be a small bug but not sure it would arise in practice.

Comment thread src/schematics/routes.jl Outdated
function hooks(rc::RouteComponent{T}) where {T}
p0 = StyledHook(
PointHook(rc.r.p0, rc.r.α0),
Paths.nextstyle(reverse(rc.sty[1], zero(T)))

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.

Not sure, but given src/paths/contstyles/trace.jl‎ does reverse(s::GeneralTrace, 0) produce GeneralTrace(t -> width(s, -t)), evaluating at negative path lengths?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It does, but my view was that it should never come up. GeneralTrace on a RouteComponent really never makes sense because you don't know the length ahead of time. You also can't terminate RouteComponents so the style can't be used there anyway.

A related problem is that nextstyle just repeats the GeneralTrace, so neither hook's style is really correct (e.g. for verifying that it matches whatever it's fused to) whether the correct pathlength is there or not. This should maybe be treated as a bug -- arguably the next style should be a constant trace with whatever the segment ended with, the same as a taper. I can't think of a case where you'd want to just repeat the GeneralTrace; if you're trying to make something periodic, you would use it inside an actual PeriodicStyle. If we fix that then at least once the path has been built the p1 style will be correct. I'll change 0 to pathlength(rc._path) so it's at least consistent if we apply that fix.

Comment thread src/paths/paths.jl Outdated
p0_hook(pa::Path, right_handed=true) = HandedPointHook(p0(pa), α0(pa), right_handed)
p0_hook(pa::Path, right_handed=true) = StyledHook(
HandedPointHook(p0(pa), α0(pa), right_handed),
isempty(pa.nodes) ? nothing : nextstyle(without_attachments(reverse(pa[1]).sty))

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.

Nit: this computes both a reversed segment and a reversed style, but only style is used so segment reversal is wasted work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair enough, changed to reverse(pa[1].sty, pathlength(pa[1].seg))

gpeairs added 3 commits May 27, 2026 13:21
Adds a `StyledHook{T, H<:Hook{T}, S} <: Hook{T}` wrapper that augments any
`Hook` with a carried path-style object, plus graph-level `terminate!`
methods that use the carried style (or an explicit `style=` kwarg) to
attach a termination cap to a schematic node's hook.
@gpeairs gpeairs force-pushed the gp/self-termination branch from 40e67dc to 503d9fa Compare May 27, 2026 11:21
@gpeairs gpeairs merged commit e7e92f8 into main May 28, 2026
10 checks passed
@gpeairs gpeairs deleted the gp/self-termination branch May 28, 2026 09:38
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.

2 participants