Add oneOfL: exactly-one-of-concepts constraint (fixes #371)#441
Open
Ashut0sh-mishra wants to merge 1 commit into
Open
Add oneOfL: exactly-one-of-concepts constraint (fixes #371)#441Ashut0sh-mishra wants to merge 1 commit into
Ashut0sh-mishra wants to merge 1 commit into
Conversation
HLR#371) Introduces oneOfL (and its accumulated sibling oneOfAL) — counting constraints with limitOp == '==' and fixedLimit = 1 that cannot be overridden by a trailing int. Makes `exactly one of these concepts holds` a first-class, intent-revealing LC, directly answering issue HLR#371. atMostL(c1,c2,c3) would permit zero; oneOfL does not. Co-authored-by: nik464 <nikhil18chaudhary@gmail.com>
b486892 to
fe9e10a
Compare
Contributor
Author
|
@kordjamshidi Hi, just checking in on this PR whenever you get a chance to review it. |
Member
|
Thank you very much for the reminder @Ashut0sh-mishra . @auszok could you also review this? |
Contributor
Author
|
Hi @auszok and @kordjamshidi, Just following up on this PR when you have a chance. Since it addresses issue #371, I'd be happy to make any changes or revisions needed after review. Thanks again for your time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #371.
The issue asks how to express "for each (step, entity), exactly one of
action_create,action_move,action_destroycan be correct". The maintainer noted thatatMostL(...)alone allows none to be true — which isn't what the user wanted — and that the clean answer needed "another constraint requiring that action has some class".This PR introduces
oneOfL(and its accumulated siblingoneOfAL) — a first-class, intent-revealing LC meaning "exactly one of these concept applications holds per candidate". It is semanticallyexactL(c1, c2, ..., 1)with one crucial difference: the limit is pinned viafixedLimit = 1and cannot be silently shifted by a trailing integer.Usage
Contrast:
atMostL(c1, c2, c3)— ≤1 true, including 0 (the issue's footgun).exactL(c1, c2, c3)— ==1 true, butexactL(c1, c2, c3, 2)silently means "==2" becauseexactLreads a trailing int as the limit.oneOfL(c1, c2, c3)— ==1, always. Trailing ints are ignored becausefixedLimittakes precedence in_CountBaseL.__call__.Changes
domiknows/graph/logicalConstrain.py— newoneOfL/oneOfALclasses. Trivial subclasses of_CountBaseL/_AccumulatedCountBaseLwithlimitOp = '=='andfixedLimit = 1. Full docstring showing the issue's own example.domiknows/graph/__init__.py— re-exportsoneOfLandoneOfALalongside the existingexactL/atMostL/etc.domiknows/solver/adaptiveTNormLossCalculator.py— adds both names toCOUNTING_CONSTRAINTSandDEFAULT_TNORM_BY_TYPE('L' mode), and mapsoneOfL → oneOfALinget_constraint_type's normaliser so they slot into the adaptive-t-norm pipeline exactly likeexactL.Backward compatibility
Additive only.
exactL,atMostL,atLeastL,existsLand friends are unchanged; existing users keep identical semantics. No signatures or defaults were altered anywhere.Tests
test_regr/test_oneofl_between_concepts.py— 10 targeted tests covering:limitOp == '==',fixedLimit == 1).domiknows.graph.exactL(..., 1)and explicit contrast with theexactL(..., k)footgun that motivated the new class.test_regr/test_oneofl_stress.py— randomised sweeps:(concepts, trailing int)combos confirmingoneOfLalways resolves to limit 1.exactL's trailing-int behaviour is preserved (back-compat guard).DOMIKNOWS_RUN_HEAVY=1.DOMIKNOWS_ONEOFL_STRESS_ITERS.Local results:
Neighbouring suites (
test_existsL_variable_scope,test_copt_pluggable,test_inference_program_modes) also run clean — 35 passed, no regressions.Co-authored-by: nik464 nikhil18chaudhary@gmail.com