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

[FR] Proposition Uniqueness #108

Closed
1 of 3 tasks
haz opened this issue Aug 28, 2024 · 0 comments · Fixed by #109
Closed
1 of 3 tasks

[FR] Proposition Uniqueness #108

haz opened this issue Aug 28, 2024 · 0 comments · Fixed by #109
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@haz
Copy link
Contributor

haz commented Aug 28, 2024

Willingness to contribute

The Bauhaus Community encourages new feature contributions. Would you be willing to contribute an implementation of this feature?

  • Yes. I can contribute this feature independently.
  • Yes. I would be willing to contribute this feature with guidance from the Bauhaus community.
  • No. I cannot contribute this feature at this time.

Proposal Summary

Proposition objects are created as unique, and so if you create multiple copies for various constraints, then it can lead to unintuitive bugs. By default, we should have a proposition be uniquely identified by it's representation (or a hash of that), and then we can create the object repeatedly and refer to the same proposition in the code.

Motivation

Is your feature request related to a problem? Please describe.

This shows what currently doesn't work, but should:

from bauhaus import Encoding, proposition, constraint

e = Encoding()

@proposition(e)
class V(object):
    pass

# Works: x refers to the same proposition
x = V('x')
y = V('y')
z = V('z')
E.add_constraint(x | y)
E.add_constraint(x | z)

# Doesn't work: each x is a unique proposition
E.add_constraint(V('x') | V('y'))
E.add_constraint(V('x') | V('y'))

While it doesn't seem like that much of a difference here, it can be largely problematic for large encodings with several variables.

Describe the solution you'd like

  • Force implementers to define the method _prop_name on their objects using @proposition. If it's not there, throw an error.
  • Return the outcome of this method for __repr__.
  • Overload __hash__ and __eq__ appropriately (e.g., [this hack]).

Why is it currently difficult to achieve this with Bauhaus?
It's not implemented.

@haz haz added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 28, 2024
@connoralittle connoralittle self-assigned this Aug 28, 2024
@connoralittle connoralittle linked a pull request Aug 28, 2024 that will close this issue
@haz haz closed this as completed in #109 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants