Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3dc4286
a predicate assumption class
christianbean Jul 19, 2022
2ea58d3
update strategies (except fusion and factor) with predicates
christianbean Jul 19, 2022
929aa63
a predicate refinement strategy
christianbean Jul 20, 2022
4dfb74a
the refinement strategy
christianbean Jul 20, 2022
b3ce42b
a parity scope class
christianbean Jul 21, 2022
3ebe3f4
some tidy up
christianbean Jul 21, 2022
14f74bb
an experimental is empty check
christianbean Jul 21, 2022
cdae45e
factor toggles parity
christianbean Jul 21, 2022
61ac5cb
add to fusion strategy
christianbean Jul 21, 2022
96fedd1
fix experimental check
christianbean Jul 21, 2022
e43524e
plus 4 for experimental check
christianbean Jul 21, 2022
cd43afa
experimental check
christianbean Jul 21, 2022
a26cb7e
some atom counting
christianbean Jul 21, 2022
23a497e
add predicate strategy to verified packs
christianbean Jul 21, 2022
718d431
code to count fusion
christianbean Jul 21, 2022
0dcffb4
experimental is empty used to determine if factor is reversible
christianbean Jul 22, 2022
0f1f060
points cells can not be even
christianbean Jul 22, 2022
19a5d05
creates requirements covering odd cells
jaypantone Jul 22, 2022
91c7b49
Merge branch 'develop' into predicates
christianbean Jul 22, 2022
27e01a4
more accurate shifts
christianbean Jul 22, 2022
1377acc
reset cached properties
christianbean Jul 25, 2022
a985f26
check if empty before and after simplify
christianbean Jul 25, 2022
2efa45c
check preds after clean assumptions
christianbean Jul 25, 2022
43b7340
is reversible in Factor class
christianbean Jul 25, 2022
a02faef
split parity cells in initialiser, and refine one pred at a time
christianbean Jul 26, 2022
022f7b0
catches corner cases
jaypantone Jul 26, 2022
7f1e990
fusion constructor considers odd left better, add assumption simplifies
christianbean Jul 27, 2022
73e00bb
fusion sampling
christianbean Jul 27, 2022
20005d9
maps in pred refinement
christianbean Jul 27, 2022
9d73060
tidy code, add debug setting in tiling.py
christianbean Jul 27, 2022
2158daf
Merge branch 'develop' into predicates
christianbean Jul 27, 2022
65cb3f5
possibly empty has to be set since our is empty check is not perfect
christianbean Jul 27, 2022
b81aa85
obsinferral is possibly empty;
christianbean Jul 27, 2022
c7c5729
a local expansion in is empty
christianbean Jul 28, 2022
31b6ea5
a smarter predicates imply empty method (#493)
christianbean Jul 28, 2022
2174602
add length 2 reqs in is empty call
christianbean Jul 28, 2022
59d49b6
smarter min sizes, and bound to experimental
christianbean Jul 28, 2022
d472e6e
not implemented reverse fusion counting
christianbean Jul 29, 2022
9e6f952
dont check init for dummy tiling
christianbean Jul 29, 2022
de521ae
insert mgps to satisfy odd even in is empty
christianbean Jul 29, 2022
d09daf1
place points not on own row and col in is empty
christianbean Jul 29, 2022
0e617ea
remove point placement in is_empty and adds experimental_bound argument
jaypantone Jul 29, 2022
d9ac524
fixes experimental bound flag
jaypantone Jul 30, 2022
9209dd5
Merge branch 'develop' into predicates
christianbean Jan 25, 2023
e1a005f
mypy/pylint/flake8 tidying up
christianbean Jan 25, 2023
a176b08
override pack in parity scope
christianbean Jan 30, 2023
3065726
Merge branch 'develop' into predicates-and-develop
christianbean Mar 20, 2023
3dd2ba0
Merge branch 'develop' into predicates
christianbean Mar 20, 2023
4dd068f
possibly empty is an argument to some strategies
christianbean Mar 20, 2023
ba70733
moving css stuff that was specific to tilings
christianbean Mar 22, 2023
c44d7bc
adding a test for av(132)
christianbean Mar 22, 2023
5ec1e7f
only do more complicated empty if necessary
christianbean Mar 22, 2023
98f2a9e
tidying up
christianbean Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions tests/strategies/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,36 +236,44 @@ def pointonly_partial_ignoreparent_dirs(strategy):
]


def partition_ignoreparent_workable(strategy):
def partition_ignoreparent_workable_possibly_empty(strategy):
return [
strategy(partition=partition, ignore_parent=ignore_parent, workable=workable)
for partition, ignore_parent, workable in product(
strategy(
partition=partition,
ignore_parent=ignore_parent,
workable=workable,
possibly_empty=possibly_empty,
)
for partition, ignore_parent, workable, possibly_empty in product(
(
[[(2, 1), (0, 1)], [(1, 0)]],
(((0, 0), (0, 2)), ((0, 1),), ((3, 3), (4, 3))),
),
(True, False),
(True, False),
(True, False),
)
]


def partition_ignoreparent_workable_tracked(strategy):
def partition_ignoreparent_workable_possibly_empty_tracked(strategy):
return [
strategy(
partition=partition,
ignore_parent=ignore_parent,
workable=workable,
possibly_empty=possibly_empty,
tracked=tracked,
)
for partition, ignore_parent, workable, tracked in product(
for partition, ignore_parent, workable, possibly_empty, tracked in product(
(
[[(2, 1), (0, 1)], [(1, 0)]],
(((0, 0), (0, 2)), ((0, 1),), ((3, 3), (4, 3))),
),
(True, False),
(True, False),
(True, False),
(True, False),
)
]

Expand Down Expand Up @@ -302,21 +310,24 @@ def gps_ignoreparent_limited(factory):
]


def gps_indices_direction_owncol_ownrow_ignoreparent_includeempty(strategy):
def gps_indices_direction_owncol_ownrow_ignoreparent_includeempty_possibly_empty(
strategy,
):
return [
strategy(
gps=gps,
indices=indices,
direction=direction,
own_col=own_col,
own_row=own_row,
ignore_parent=ignore_parent,
include_empty=include_empty,
ignore_parent=ign_par,
include_empty=inc_empty,
possibly_empty=pos_empty,
)
for (
gps,
indices,
), direction, own_col, own_row, ignore_parent, include_empty in product(
), direction, own_col, own_row, ign_par, inc_empty, pos_empty in product(
(
((GriddedPerm((0,), ((0, 0),)),), (0,)),
((GriddedPerm.single_cell((0, 1, 2), (2, 1)),), (1,)),
Expand All @@ -333,6 +344,7 @@ def gps_indices_direction_owncol_ownrow_ignoreparent_includeempty(strategy):
(True, False),
(True, False),
(True, False),
(True, False),
)
]

Expand Down Expand Up @@ -401,9 +413,13 @@ def indices_and_row(strategy):
+ maxreqlen_extrabasis_ignoreparent(RequirementInsertionFactory)
+ subreqs_partial_ignoreparent_dirs(RequirementPlacementFactory)
+ [SymmetriesFactory(), BasicVerificationStrategy(), EmptyCellInferralFactory()]
+ partition_ignoreparent_workable(FactorStrategy)
+ partition_ignoreparent_workable_tracked(FactorWithInterleavingStrategy)
+ partition_ignoreparent_workable_tracked(FactorWithMonotoneInterleavingStrategy)
+ partition_ignoreparent_workable_possibly_empty(FactorStrategy)
+ partition_ignoreparent_workable_possibly_empty_tracked(
FactorWithInterleavingStrategy
)
+ partition_ignoreparent_workable_possibly_empty_tracked(
FactorWithMonotoneInterleavingStrategy
)
+ ignoreparent(DatabaseVerificationStrategy)
+ ignoreparent(LocallyFactorableVerificationStrategy)
+ ignoreparent(ElementaryVerificationStrategy)
Expand Down Expand Up @@ -445,7 +461,7 @@ def indices_and_row(strategy):
+ ignoreparent(RequirementCorroborationFactory)
+ gps_ignoreparent(RequirementInsertionStrategy)
+ gps_ignoreparent_limited(RequirementInsertionFactory)
+ gps_indices_direction_owncol_ownrow_ignoreparent_includeempty(
+ gps_indices_direction_owncol_ownrow_ignoreparent_includeempty_possibly_empty(
RequirementPlacementStrategy
)
+ maxreqlen_extrabasis_ignoreparent_maxnumreq(RootInsertionFactory)
Expand Down Expand Up @@ -475,7 +491,14 @@ def indices_and_row(strategy):
DeflationStrategy((4, 1), False, False),
]
+ [ComponentFusionFactory()]
+ [ObstructionInferralStrategy([GriddedPerm((0, 1, 2), ((0, 0), (1, 1), (1, 2)))])]
+ [
ObstructionInferralStrategy(
[GriddedPerm((0, 1, 2), ((0, 0), (1, 1), (1, 2)))], possibly_empty=True
),
ObstructionInferralStrategy(
[GriddedPerm((0, 1, 2), ((0, 0), (1, 1), (1, 2)))], possibly_empty=False
),
]
+ [
SplittingStrategy(),
SplittingStrategy("none"),
Expand Down
3 changes: 3 additions & 0 deletions tests/strategies/test_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def test_rule(
assert all(rule.inferrable for rule in factor_with_int_rules)
assert all(len(rule.strategy.partition) == len(rule.children) for rule in all_rules)
assert all(rule.workable for rule in all_rules)
for rule in all_rules:
print(rule)
print(rule.possibly_empty)
assert all(not rule.possibly_empty for rule in all_rules)
assert all(rule.ignore_parent for rule in all_rules)
assert not list(FactorFactory(interleaving="all")(not_fact_tiling))
Expand Down
2 changes: 1 addition & 1 deletion tests/strategies/test_inferral.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_row_col_sep(tiling1):
assert isinstance(rule.constructor, DisjointUnion)
assert rule.formal_step == "row and column separation"
assert rule.inferrable
assert not rule.possibly_empty
assert rule.possibly_empty
assert rule.ignore_parent
assert rule.workable
assert rule.children[0] == Tiling(
Expand Down
2 changes: 1 addition & 1 deletion tests/strategies/test_row_column_separation.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_rule(seperable_tiling1, not_separable_tilings):
assert rule.ignore_parent
assert rule.workable
assert isinstance(rule.constructor, DisjointUnion)
assert not rule.possibly_empty
assert rule.possibly_empty
assert (
RowColumnSeparationStrategy().decomposition_function(not_separable_tilings[0])
is None
Expand Down
25 changes: 21 additions & 4 deletions tests/strategies/test_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from tilings.strategies.detect_components import DetectComponentsStrategy
from tilings.strategies.experimental_verification import SubclassVerificationStrategy
from tilings.strategies.predicate_refinement import RefinePredicatesStrategy
from tilings.tilescope import TileScopePack


Expand Down Expand Up @@ -472,6 +473,8 @@ def test_pack(self, strategy, enum_verified):
enum_verified[0]
) == TileScopePack.regular_insertion_encoding(3).add_initial(
DetectComponentsStrategy()
).add_initial(
RefinePredicatesStrategy(), apply_first=True
)
assert strategy.pack(enum_verified[1]).name == "factor pack"
assert strategy.pack(enum_verified[2]).name == "factor pack"
Expand Down Expand Up @@ -663,6 +666,8 @@ def test_pack(self, strategy, enum_verified):
enum_verified[1]
) == TileScopePack.regular_insertion_encoding(3).add_initial(
DetectComponentsStrategy()
).add_initial(
RefinePredicatesStrategy(), apply_first=True
)

@pytest.mark.timeout(30)
Expand Down Expand Up @@ -999,23 +1004,35 @@ def test_pack(self, strategy, enum_verified):
enum_verified[0]
) == TileScopePack.point_and_row_and_col_placements().add_verification(
BasicVerificationStrategy(), replace=True
).add_initial(
RefinePredicatesStrategy(), apply_first=True
)
assert strategy.pack(enum_verified[1]) in (
TileScopePack.regular_insertion_encoding(2),
TileScopePack.regular_insertion_encoding(3),
TileScopePack.regular_insertion_encoding(2).add_initial(
RefinePredicatesStrategy(), apply_first=True
),
TileScopePack.regular_insertion_encoding(3).add_initial(
RefinePredicatesStrategy(), apply_first=True
),
)

assert strategy.pack(
enum_verified[2]
) == TileScopePack.regular_insertion_encoding(3)
) == TileScopePack.regular_insertion_encoding(3).add_initial(
RefinePredicatesStrategy(), apply_first=True
)

assert strategy.pack(
enum_verified[3]
) == TileScopePack.regular_insertion_encoding(2)
) == TileScopePack.regular_insertion_encoding(2).add_initial(
RefinePredicatesStrategy(), apply_first=True
)
assert strategy.pack(
enum_verified[4]
) == TileScopePack.row_and_col_placements().add_basis(
[Perm((0, 1, 2)), Perm((2, 3, 0, 1))]
).add_initial(
RefinePredicatesStrategy(), apply_first=True
)

# assert strategy.pack(
Expand Down
32 changes: 32 additions & 0 deletions tests/test_predicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from comb_spec_searcher import CombinatorialSpecification
from tilings.tilescope import ParityScope, TileScopePack

point_placements = TileScopePack.point_placements()


@pytest.mark.timeout(20)
def test_132():
searcher = ParityScope("132", point_placements, max_assumptions=100)
spec = searcher.auto_search(smallest=True)
assert isinstance(spec, CombinatorialSpecification)
spec = spec.expand_verified()
for i in range(10):
actual = set(spec.root.objects_of_size(i))
assert actual == set(spec.generate_objects_of_size(i))
assert spec.random_sample_object_of_size(i) in actual
assert [
1,
1,
1,
2,
3,
7,
12,
30,
55,
143,
273,
728,
] == [spec.count_objects_of_size(i) for i in range(12)]
16 changes: 14 additions & 2 deletions tilings/algorithms/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

from permuta.misc import UnionFind
from tilings import GriddedPerm
from tilings.assumptions import ComponentAssumption, TrackingAssumption
from tilings.assumptions import (
ComponentAssumption,
PredicateAssumption,
TrackingAssumption,
)
from tilings.misc import partitions_iterator

if TYPE_CHECKING:
Expand Down Expand Up @@ -76,10 +80,16 @@ def _unite_assumptions(self) -> None:
"""
For each TrackingAssumption unite all the positions of the gridded perms.
"""
if any(len(ass.cells) > 1 for ass in self._tiling.predicate_assumptions):
# DO NOT FACTOR
self._unite_cells(self._tiling.active_cells)
return
for assumption in self._tiling.assumptions:
if isinstance(assumption, ComponentAssumption):
for cells in assumption.cell_decomposition(self._tiling):
self._unite_cells(cells)
elif isinstance(assumption, PredicateAssumption):
self._unite_cells(assumption.cells)
else:
for gp in assumption.gps:
self._unite_cells(gp.pos)
Expand Down Expand Up @@ -155,6 +165,8 @@ def _get_factors_obs_and_reqs(
Returns a list of all the irreducible factors of the tiling.
Each factor is a tuple (obstructions, requirements)
"""
if self._tiling.predicate_assumptions:
raise NotImplementedError
if self._factors_obs_and_reqs is not None:
return self._factors_obs_and_reqs
if self._tiling.is_empty():
Expand All @@ -170,7 +182,7 @@ def _get_factors_obs_and_reqs(
# TODO: consider skew/sum assumptions
assumptions = tuple(
ass.__class__(gp for gp in ass.gps if gp.pos[0] in component)
for ass in self._tiling.assumptions
for ass in self._tiling.tracking_assumptions
)
factors.append(
(
Expand Down
Loading