Skip to content

Commit

Permalink
Implement reversible synthesis rules (#499)
Browse files Browse the repository at this point in the history
Currently patterns like `None | A()` are not recognised, although they
work if one reverses the order. This PR fixes reversible synthesis
rules like this, and adds some tests.
  • Loading branch information
alubbock committed Jun 4, 2020
1 parent 4ebeee0 commit dc33305
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pysb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ def __rrshift__(self, other):
def __or__(self, other):
return build_rule_expression(self, other, True)

def __ror__(self, other):
return build_rule_expression(other, self, True)

def __ne__(self, other):
warnings.warn("'<>' for reversible rules will be removed in a future "
"version of PySB. Use '|' instead.",
Expand Down Expand Up @@ -1057,6 +1060,9 @@ def __rrshift__(self, other):
def __or__(self, other):
return build_rule_expression(self, other, True)

def __ror__(self, other):
return build_rule_expression(other, self, True)

def __ne__(self, other):
warnings.warn("'<>' for reversible rules will be removed in a future "
"version of PySB. Use '|' instead.",
Expand Down
7 changes: 7 additions & 0 deletions pysb/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,10 @@ def test_parameter_negative_nonnegative_setter():
Parameter('k3', 0.0, nonnegative=True)
k3.value = -0.2


@with_model
def test_reversible_synthesis():
Monomer('A')
Parameter('k', 1)
Rule('r1', None | A(), k, k)
Rule('r2', None | as_complex_pattern(A()), k, k)

0 comments on commit dc33305

Please sign in to comment.