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

Require homomorphism to be unique #926

Merged
merged 6 commits into from
Jul 17, 2024
Merged

Require homomorphism to be unique #926

merged 6 commits into from
Jul 17, 2024

Conversation

kris-brown
Copy link
Contributor

@kris-brown kris-brown commented Jul 15, 2024

This PR involves refactoring the backtracking_search interface, which now accepts take, max, and filter keyword arguments.

  • take = number of homomorphisms requested (stop the search process early if this number is reached)
  • max = throw an error if we find more than this many morphisms (e.g. set max=1 if one expects 0 or 1 morphism)
  • filter = only consider morphisms which meet some criteria, expressed as a Julia function of type ACSetTransformation -> Bool

This allows homomorphism to be redefined as:

function homomorphism(X::ACSet, Y::ACSet, alg::BacktrackingSearch; any=false, kw...)
  res = homomorphisms(X, Y, alg; Dict((any ? :take : :max) => 1)..., kw...)
  isempty(res) ? nothing : only(res)
end

The old behavior is recovered via any=true, but this should not be default as it leads to endless user confusion. Thus there is a version bump for this breaking change.

The postprocessing logic for solutions to backtracking search (introduced recently in #918) was simplified and moved into its own function to not clutter backtracking_search.

Note: filter is needed for certain AlgebraicRewriting features, such as trying to get a single (but arbitrary) homomorphism subject to certain arbitrary constraints, such as the dangling condition, NACs, etc.

Also note: there was an unrelated bug in coerce_component for MarkAsDeleted ACSets which was unearthed in this process.

@kris-brown kris-brown self-assigned this Jul 15, 2024
@kris-brown kris-brown linked an issue Jul 15, 2024 that may be closed by this pull request
Copy link
Member

@epatters epatters left a comment

Choose a reason for hiding this comment

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

Thanks Kris, looks great! The new behavior should be much more in line with users' expectations.

src/categorical_algebra/CSets.jl Outdated Show resolved Hide resolved
src/categorical_algebra/HomSearch.jl Outdated Show resolved Hide resolved
src/categorical_algebra/HomSearch.jl Outdated Show resolved Hide resolved
@epatters epatters merged commit cd11d31 into main Jul 17, 2024
11 checks passed
@epatters epatters deleted the unique_hom branch July 17, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Homomorphism should error if there are multiple homomorphisms
2 participants