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

Throws exception when Predicate is not called #15

Merged
merged 1 commit into from Mar 16, 2022

Conversation

mikulatomas
Copy link
Contributor

In [1]: from lnn import Predicate, And
   ...: 
   ...: P = Predicate("P", arity=0)
   ...: 

In [2]: And(P(), P())
Out[2]: <lnn.symbolic.logic.And at 0x1107e4d30>

In [3]: And(P(), P)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [3], in <module>
----> 1 And(P(), P)

File ~/Gits/LNN/lnn/symbolic/logic.py:1110, in _NAryNeuron.__init__(self, *formula, **kwds)
   1109 def __init__(self, *formula, **kwds):
-> 1110     super().__init__(*formula, arity=len(formula), **kwds)

File ~/Gits/LNN/lnn/symbolic/logic.py:976, in _ConnectiveNeuron.__init__(self, *formula, **kwds)
    975 def __init__(self, *formula, **kwds):
--> 976     super().__init__(*formula, **kwds)
    977     self.neuron = _NeuralActivation(kwds.get("neuron", {}).get("type"))(
    978         self.propositional, self.arity, self.world, **kwds.get("neuron", {})
    979     )
    980     self.func = self.neuron.function(
    981         self.__class__.__name__, direction=Direction.UPWARD
    982     )

File ~/Gits/LNN/lnn/symbolic/logic.py:971, in _ConnectiveFormula.__init__(self, *formula, **kwds)
    970 def __init__(self, *formula: _Formula, **kwds):
--> 971     super().__init__(*formula, **kwds)

File ~/Gits/LNN/lnn/symbolic/logic.py:156, in _Formula.__init__(self, name, arity, world, *formula, **kwds)
    154     for subformula in formula:
    155         if isinstance(subformula, Predicate):
--> 156             raise ValueError(
    157                 f"predicate {subformula} inside formula must be called"
    158             )
    160 # formula naming
    161 self.name = (
    162     name
    163     if name
    164     else (f"{self.class_name}_{_Formula.unique_num[self.class_name]}")
    165 )

ValueError: predicate P inside formula must be called

@NaweedAghmad
Copy link
Collaborator

Can we resubmit this so that travis doesn't trigger?

Black formatting


Add tests


Black formatting
@mikulatomas
Copy link
Contributor Author

Can we resubmit this so that travis doesn't trigger?

Done :)

@NaweedAghmad NaweedAghmad linked an issue Mar 16, 2022 that may be closed by this pull request
@NaweedAghmad NaweedAghmad merged commit 3dd77fb into IBM:master Mar 16, 2022
@NaweedAghmad
Copy link
Collaborator

perhaps we could wrap it similar to the content in https://github.com/IBM/LNN/blob/master/lnn/_exceptions.py?

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.

Throw exception for predicates in compound formulae w/o variables
2 participants