mapFolding 0.8.6__tar.gz → 0.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapfolding-0.9.1/PKG-INFO +177 -0
- mapfolding-0.9.1/README.md +125 -0
- mapfolding-0.9.1/mapFolding/__init__.py +93 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/basecamp.py +32 -17
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/beDRY.py +4 -5
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/oeis.py +94 -7
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/RecipeJob.py +103 -0
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/__init__.py +87 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/someAssemblyRequired/_theTypes.py +11 -15
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/someAssemblyRequired/_tool_Make.py +36 -9
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/_tool_Then.py +106 -0
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/_toolboxAntecedents.py +245 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/someAssemblyRequired/_toolboxContainers.py +155 -70
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/_toolboxPython.py +186 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +154 -39
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/toolboxNumba.py +206 -0
- mapfolding-0.9.1/mapFolding/someAssemblyRequired/transformationTools.py +606 -0
- mapfolding-0.8.6/mapFolding/syntheticModules/numbaCount_doTheNeedful.py → mapfolding-0.9.1/mapFolding/syntheticModules/numbaCount.py +7 -4
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/theDao.py +19 -16
- mapfolding-0.9.1/mapFolding/theSSOT.py +290 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/toolboxFilesystem.py +1 -1
- mapfolding-0.9.1/mapFolding.egg-info/PKG-INFO +177 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding.egg-info/SOURCES.txt +2 -2
- {mapfolding-0.8.6 → mapfolding-0.9.1}/pyproject.toml +3 -3
- mapfolding-0.9.1/tests/__init__.py +44 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/tests/conftest.py +75 -7
- mapfolding-0.9.1/tests/test_computations.py +145 -0
- mapfolding-0.9.1/tests/test_filesystem.py +49 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/tests/test_other.py +0 -1
- {mapfolding-0.8.6 → mapfolding-0.9.1}/tests/test_tasks.py +1 -1
- mapfolding-0.8.6/PKG-INFO +0 -190
- mapfolding-0.8.6/README.md +0 -139
- mapfolding-0.8.6/mapFolding/__init__.py +0 -46
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/__init__.py +0 -66
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/_tool_Then.py +0 -72
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -358
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/_toolboxPython.py +0 -62
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/newInliner.py +0 -22
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/toolboxNumba.py +0 -364
- mapfolding-0.8.6/mapFolding/someAssemblyRequired/transformationTools.py +0 -377
- mapfolding-0.8.6/mapFolding/theSSOT.py +0 -187
- mapfolding-0.8.6/mapFolding.egg-info/PKG-INFO +0 -190
- mapfolding-0.8.6/tests/__init__.py +0 -0
- mapfolding-0.8.6/tests/test_computations.py +0 -63
- mapfolding-0.8.6/tests/test_filesystem.py +0 -50
- {mapfolding-0.8.6 → mapfolding-0.9.1}/LICENSE +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/py.typed +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/__init__.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/flattened.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/jaxCount.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/jobsCompleted/__init__.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/jobsCompleted/p2x19/p2x19.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/lunnanNumpy.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/lunnanWhile.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding/syntheticModules/__init__.py +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding.egg-info/requires.txt +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/setup.cfg +0 -0
- {mapfolding-0.8.6 → mapfolding-0.9.1}/tests/test_oeis.py +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapFolding
|
|
3
|
+
Version: 0.9.1
|
|
4
|
+
Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
|
|
5
|
+
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
|
+
License: CC-BY-NC-4.0
|
|
7
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
8
|
+
Project-URL: Homepage, https://github.com/hunterhogan/mapFolding
|
|
9
|
+
Project-URL: Repository, https://github.com/hunterhogan/mapFolding.git
|
|
10
|
+
Project-URL: Issues, https://github.com/hunterhogan/mapFolding/issues
|
|
11
|
+
Keywords: A001415,A001416,A001417,A001418,A195646,algorithmic optimization,AST manipulation,code generation,code transformation,combinatorics,computational geometry,dataclass transformation,folding pattern enumeration,just-in-time compilation,map folding,Numba optimization,OEIS,performance optimization,source code analysis,stamp folding
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
27
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: autoflake
|
|
35
|
+
Requires-Dist: more_itertools
|
|
36
|
+
Requires-Dist: numba_progress
|
|
37
|
+
Requires-Dist: numba
|
|
38
|
+
Requires-Dist: numpy
|
|
39
|
+
Requires-Dist: platformdirs
|
|
40
|
+
Requires-Dist: python_minifier
|
|
41
|
+
Requires-Dist: tomli
|
|
42
|
+
Requires-Dist: Z0Z_tools
|
|
43
|
+
Provides-Extra: testing
|
|
44
|
+
Requires-Dist: mypy; extra == "testing"
|
|
45
|
+
Requires-Dist: pytest; extra == "testing"
|
|
46
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
47
|
+
Requires-Dist: pytest-env; extra == "testing"
|
|
48
|
+
Requires-Dist: pytest-xdist; extra == "testing"
|
|
49
|
+
Requires-Dist: pyupgrade; extra == "testing"
|
|
50
|
+
Requires-Dist: ruff; extra == "testing"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# mapFolding: High-Performance Algorithm Playground for Computational Enthusiasts 🗺️
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/mapFolding/)
|
|
56
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
57
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
58
|
+
|
|
59
|
+
**This package is for you if:**
|
|
60
|
+
|
|
61
|
+
- You're fascinated by computational algorithms and their optimization
|
|
62
|
+
- You want to explore AST transformation techniques for Python performance tuning
|
|
63
|
+
- You're interested in solving mathematical puzzles through code
|
|
64
|
+
- You're learning about Numba and advanced Python optimization
|
|
65
|
+
|
|
66
|
+
**This package is NOT for you if:**
|
|
67
|
+
|
|
68
|
+
- You're looking for a general-purpose folding simulation tool
|
|
69
|
+
- You need commercial-ready mapping software
|
|
70
|
+
- You want simple visualization of folding patterns
|
|
71
|
+
|
|
72
|
+
## What Does This Package Actually Do?
|
|
73
|
+
|
|
74
|
+
`mapFolding` solves a specific mathematical problem: counting the number of distinct ways to fold a rectangular map. While this may sound niche, it's a fascinating computational challenge that demonstrates:
|
|
75
|
+
|
|
76
|
+
1. How to transform readable algorithms into blazingly fast implementations
|
|
77
|
+
2. Advanced techniques for Python optimization using AST manipulation
|
|
78
|
+
3. Numba acceleration with specialized compilation strategies
|
|
79
|
+
4. Algorithms for problems that grow combinatorially
|
|
80
|
+
|
|
81
|
+
The package has achieved new computational records, including first-ever calculations for large maps that were previously infeasible.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
# Compute the number of ways to fold a 5×5 grid:
|
|
85
|
+
from mapFolding import oeisIDfor_n
|
|
86
|
+
foldsTotal = oeisIDfor_n('A001418', 5) # Returns 186,086,600
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Key Benefits for Computational Enthusiasts
|
|
90
|
+
|
|
91
|
+
### 1. Algorithm Transformation Laboratory
|
|
92
|
+
|
|
93
|
+
See how the same algorithm evolves from readable Python to highly-optimized implementations:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# The intuitive, readable version:
|
|
97
|
+
def countFolds(mapShape):
|
|
98
|
+
# ...implement readable algorithm...
|
|
99
|
+
|
|
100
|
+
# The transformed, optimized version (auto-generated):
|
|
101
|
+
@numba.jit(nopython=True, parallel=True, fastmath=True)
|
|
102
|
+
def countFolds_optimized(shape_param):
|
|
103
|
+
# ...blazingly fast implementation...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 2. Code Generation Framework
|
|
107
|
+
|
|
108
|
+
Study and extend a complete Python code transformation pipeline:
|
|
109
|
+
|
|
110
|
+
- AST analysis and manipulation
|
|
111
|
+
- Dataclass decomposition ("shattering")
|
|
112
|
+
- Automatic import management
|
|
113
|
+
- Type specialization for numerical computing
|
|
114
|
+
|
|
115
|
+
### 3. Exhaustive Test Framework
|
|
116
|
+
|
|
117
|
+
Leverage a sophisticated test suite for validating your own optimizations:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# Test your own recipe implementation with just a few lines:
|
|
121
|
+
@pytest.fixture
|
|
122
|
+
def myCustomRecipeFixture(useThisDispatcher, pathTmpTesting):
|
|
123
|
+
myRecipe = RecipeSynthesizeFlow(
|
|
124
|
+
# Your custom configuration here
|
|
125
|
+
)
|
|
126
|
+
# ...transformation code...
|
|
127
|
+
return customDispatcher
|
|
128
|
+
|
|
129
|
+
def test_myCustomImplementation(myCustomRecipeFixture):
|
|
130
|
+
# Automatic validation against known values
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Installation and Getting Started
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
pip install mapFolding
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Try a quick calculation:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from mapFolding import oeisIDfor_n
|
|
143
|
+
|
|
144
|
+
# Calculate ways to fold a 2×4 map
|
|
145
|
+
result = oeisIDfor_n('A001415', 4) # Returns 8
|
|
146
|
+
print(f"A 2×4 map can be folded {result} different ways")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Mathematical Background (For the Curious)
|
|
150
|
+
|
|
151
|
+
The map folding problem was introduced by Lunnon in 1971 and connects to combinatorial geometry, computational complexity, and integer sequence analysis. The calculations provide entries to the Online Encyclopedia of Integer Sequences (OEIS).
|
|
152
|
+
|
|
153
|
+
This package implements several OEIS sequences, including:
|
|
154
|
+
|
|
155
|
+
- A001415: Number of ways to fold a 2×n strip (now calculated up to n=20!)
|
|
156
|
+
- A001418: Number of ways to fold an n×n square grid
|
|
157
|
+
|
|
158
|
+
## Explore the Repository
|
|
159
|
+
|
|
160
|
+
The repository structure reveals the package's educational value:
|
|
161
|
+
|
|
162
|
+
- `reference/`: Historical implementations and algorithm evolution
|
|
163
|
+
- `someAssemblyRequired/`: Code transformation framework
|
|
164
|
+
- `tests/`: Comprehensive test suite with fixtures for your own implementations
|
|
165
|
+
|
|
166
|
+
## Who Is This For, Really?
|
|
167
|
+
|
|
168
|
+
If you've read this far and are intrigued by computational puzzles, algorithm optimization, or Python performance techniques, this package offers a playground for exploration. It's particularly valuable for:
|
|
169
|
+
|
|
170
|
+
- Computer science students studying algorithm optimization
|
|
171
|
+
- Python developers exploring Numba and AST manipulation
|
|
172
|
+
- Computational mathematicians interested in combinatorial problems
|
|
173
|
+
- Anyone fascinated by the intersection of mathematics and computing
|
|
174
|
+
|
|
175
|
+
Whether you use it to solve map folding problems or to study its optimization techniques, `mapFolding` offers a unique window into advanced Python programming approaches.
|
|
176
|
+
|
|
177
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# mapFolding: High-Performance Algorithm Playground for Computational Enthusiasts 🗺️
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/mapFolding/)
|
|
4
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
5
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
6
|
+
|
|
7
|
+
**This package is for you if:**
|
|
8
|
+
|
|
9
|
+
- You're fascinated by computational algorithms and their optimization
|
|
10
|
+
- You want to explore AST transformation techniques for Python performance tuning
|
|
11
|
+
- You're interested in solving mathematical puzzles through code
|
|
12
|
+
- You're learning about Numba and advanced Python optimization
|
|
13
|
+
|
|
14
|
+
**This package is NOT for you if:**
|
|
15
|
+
|
|
16
|
+
- You're looking for a general-purpose folding simulation tool
|
|
17
|
+
- You need commercial-ready mapping software
|
|
18
|
+
- You want simple visualization of folding patterns
|
|
19
|
+
|
|
20
|
+
## What Does This Package Actually Do?
|
|
21
|
+
|
|
22
|
+
`mapFolding` solves a specific mathematical problem: counting the number of distinct ways to fold a rectangular map. While this may sound niche, it's a fascinating computational challenge that demonstrates:
|
|
23
|
+
|
|
24
|
+
1. How to transform readable algorithms into blazingly fast implementations
|
|
25
|
+
2. Advanced techniques for Python optimization using AST manipulation
|
|
26
|
+
3. Numba acceleration with specialized compilation strategies
|
|
27
|
+
4. Algorithms for problems that grow combinatorially
|
|
28
|
+
|
|
29
|
+
The package has achieved new computational records, including first-ever calculations for large maps that were previously infeasible.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
# Compute the number of ways to fold a 5×5 grid:
|
|
33
|
+
from mapFolding import oeisIDfor_n
|
|
34
|
+
foldsTotal = oeisIDfor_n('A001418', 5) # Returns 186,086,600
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Key Benefits for Computational Enthusiasts
|
|
38
|
+
|
|
39
|
+
### 1. Algorithm Transformation Laboratory
|
|
40
|
+
|
|
41
|
+
See how the same algorithm evolves from readable Python to highly-optimized implementations:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
# The intuitive, readable version:
|
|
45
|
+
def countFolds(mapShape):
|
|
46
|
+
# ...implement readable algorithm...
|
|
47
|
+
|
|
48
|
+
# The transformed, optimized version (auto-generated):
|
|
49
|
+
@numba.jit(nopython=True, parallel=True, fastmath=True)
|
|
50
|
+
def countFolds_optimized(shape_param):
|
|
51
|
+
# ...blazingly fast implementation...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Code Generation Framework
|
|
55
|
+
|
|
56
|
+
Study and extend a complete Python code transformation pipeline:
|
|
57
|
+
|
|
58
|
+
- AST analysis and manipulation
|
|
59
|
+
- Dataclass decomposition ("shattering")
|
|
60
|
+
- Automatic import management
|
|
61
|
+
- Type specialization for numerical computing
|
|
62
|
+
|
|
63
|
+
### 3. Exhaustive Test Framework
|
|
64
|
+
|
|
65
|
+
Leverage a sophisticated test suite for validating your own optimizations:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
# Test your own recipe implementation with just a few lines:
|
|
69
|
+
@pytest.fixture
|
|
70
|
+
def myCustomRecipeFixture(useThisDispatcher, pathTmpTesting):
|
|
71
|
+
myRecipe = RecipeSynthesizeFlow(
|
|
72
|
+
# Your custom configuration here
|
|
73
|
+
)
|
|
74
|
+
# ...transformation code...
|
|
75
|
+
return customDispatcher
|
|
76
|
+
|
|
77
|
+
def test_myCustomImplementation(myCustomRecipeFixture):
|
|
78
|
+
# Automatic validation against known values
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Installation and Getting Started
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
pip install mapFolding
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Try a quick calculation:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from mapFolding import oeisIDfor_n
|
|
91
|
+
|
|
92
|
+
# Calculate ways to fold a 2×4 map
|
|
93
|
+
result = oeisIDfor_n('A001415', 4) # Returns 8
|
|
94
|
+
print(f"A 2×4 map can be folded {result} different ways")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Mathematical Background (For the Curious)
|
|
98
|
+
|
|
99
|
+
The map folding problem was introduced by Lunnon in 1971 and connects to combinatorial geometry, computational complexity, and integer sequence analysis. The calculations provide entries to the Online Encyclopedia of Integer Sequences (OEIS).
|
|
100
|
+
|
|
101
|
+
This package implements several OEIS sequences, including:
|
|
102
|
+
|
|
103
|
+
- A001415: Number of ways to fold a 2×n strip (now calculated up to n=20!)
|
|
104
|
+
- A001418: Number of ways to fold an n×n square grid
|
|
105
|
+
|
|
106
|
+
## Explore the Repository
|
|
107
|
+
|
|
108
|
+
The repository structure reveals the package's educational value:
|
|
109
|
+
|
|
110
|
+
- `reference/`: Historical implementations and algorithm evolution
|
|
111
|
+
- `someAssemblyRequired/`: Code transformation framework
|
|
112
|
+
- `tests/`: Comprehensive test suite with fixtures for your own implementations
|
|
113
|
+
|
|
114
|
+
## Who Is This For, Really?
|
|
115
|
+
|
|
116
|
+
If you've read this far and are intrigued by computational puzzles, algorithm optimization, or Python performance techniques, this package offers a playground for exploration. It's particularly valuable for:
|
|
117
|
+
|
|
118
|
+
- Computer science students studying algorithm optimization
|
|
119
|
+
- Python developers exploring Numba and AST manipulation
|
|
120
|
+
- Computational mathematicians interested in combinatorial problems
|
|
121
|
+
- Anyone fascinated by the intersection of mathematics and computing
|
|
122
|
+
|
|
123
|
+
Whether you use it to solve map folding problems or to study its optimization techniques, `mapFolding` offers a unique window into advanced Python programming approaches.
|
|
124
|
+
|
|
125
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Map folding enumeration and counting algorithms with advanced optimization capabilities.
|
|
3
|
+
|
|
4
|
+
This package implements algorithms to count and enumerate the distinct ways
|
|
5
|
+
a rectangular map can be folded, based on the mathematical problem described
|
|
6
|
+
in Lunnon's 1971 paper. It provides multiple layers of functionality, from
|
|
7
|
+
high-level user interfaces to sophisticated algorithmic optimizations and code
|
|
8
|
+
transformation tools.
|
|
9
|
+
|
|
10
|
+
Core modules:
|
|
11
|
+
- basecamp: Public API with simplified interfaces for end users
|
|
12
|
+
- theDao: Core computational algorithm using a functional state-transformation approach
|
|
13
|
+
- beDRY: Core utility functions implementing consistent data handling, validation, and
|
|
14
|
+
resource management across the package's computational assembly-line
|
|
15
|
+
- theSSOT: Single Source of Truth for configuration, types, and state management
|
|
16
|
+
- toolboxFilesystem: Cross-platform file management services for storing and retrieving
|
|
17
|
+
computation results with robust error handling and fallback mechanisms
|
|
18
|
+
- oeis: Interface to the Online Encyclopedia of Integer Sequences for known results
|
|
19
|
+
|
|
20
|
+
Extended functionality:
|
|
21
|
+
- someAssemblyRequired: Code transformation framework that optimizes the core algorithm
|
|
22
|
+
through AST manipulation, dataclass transformation, and compilation techniques
|
|
23
|
+
- The system converts readable code into high-performance implementations through
|
|
24
|
+
a systematic analysis and transformation pipeline
|
|
25
|
+
- Provides tools to "shatter" complex dataclasses into primitive components,
|
|
26
|
+
enabling compatibility with Numba and other optimization frameworks
|
|
27
|
+
- Creates specialized implementations tailored for specific input parameters
|
|
28
|
+
|
|
29
|
+
Testing and extension:
|
|
30
|
+
- tests: Comprehensive test suite designed for both verification and extension
|
|
31
|
+
- Provides fixtures and utilities that simplify testing of custom implementations
|
|
32
|
+
- Enables users to validate their own recipes and job configurations with minimal code
|
|
33
|
+
- Offers standardized testing patterns that maintain consistency across the codebase
|
|
34
|
+
- See tests/__init__.py for detailed documentation on extending the test suite
|
|
35
|
+
|
|
36
|
+
Special directories:
|
|
37
|
+
- .cache/: Stores cached data from external sources like OEIS to improve performance
|
|
38
|
+
- syntheticModules/: Contains dynamically generated, optimized implementations of the
|
|
39
|
+
core algorithm created by the code transformation framework
|
|
40
|
+
- reference/: Historical implementations and educational resources for algorithm exploration
|
|
41
|
+
- reference/jobsCompleted/: Contains successful computations for previously unknown values,
|
|
42
|
+
including first-ever calculations for 2x19 and 2x20 maps (OEIS A001415)
|
|
43
|
+
|
|
44
|
+
This package balances algorithm readability and understandability with
|
|
45
|
+
high-performance computation capabilities, allowing users to compute map folding
|
|
46
|
+
totals for larger dimensions than previously feasible while also providing
|
|
47
|
+
a foundation for exploring advanced code transformation techniques.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
'clearOEIScache',
|
|
52
|
+
'countFolds',
|
|
53
|
+
'getOEISids',
|
|
54
|
+
'OEIS_for_n',
|
|
55
|
+
'oeisIDfor_n',
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
from mapFolding.theSSOT import (
|
|
59
|
+
Array1DElephino,
|
|
60
|
+
Array1DFoldsTotal,
|
|
61
|
+
Array1DLeavesTotal,
|
|
62
|
+
Array3D,
|
|
63
|
+
ComputationState,
|
|
64
|
+
DatatypeElephino,
|
|
65
|
+
DatatypeFoldsTotal,
|
|
66
|
+
DatatypeLeavesTotal,
|
|
67
|
+
NumPyElephino,
|
|
68
|
+
NumPyFoldsTotal,
|
|
69
|
+
NumPyIntegerType,
|
|
70
|
+
NumPyLeavesTotal,
|
|
71
|
+
raiseIfNoneGitHubIssueNumber3,
|
|
72
|
+
The,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
from mapFolding.theDao import countInitialize, doTheNeedful
|
|
76
|
+
|
|
77
|
+
from mapFolding.beDRY import (
|
|
78
|
+
outfitCountFolds,
|
|
79
|
+
setProcessorLimit,
|
|
80
|
+
validateListDimensions,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
from mapFolding.toolboxFilesystem import (
|
|
84
|
+
getPathFilenameFoldsTotal,
|
|
85
|
+
getPathRootJobDEFAULT,
|
|
86
|
+
saveFoldsTotal,
|
|
87
|
+
saveFoldsTotalFAILearly,
|
|
88
|
+
writeStringToHere,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
from mapFolding.basecamp import countFolds
|
|
92
|
+
|
|
93
|
+
from mapFolding.oeis import clearOEIScache, getFoldsTotalKnown, getOEISids, OEIS_for_n, oeisIDfor_n
|
|
@@ -13,9 +13,16 @@ implementation, and optional persistence of results.
|
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
from collections.abc import Sequence
|
|
16
|
-
from mapFolding
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
from mapFolding import (
|
|
17
|
+
ComputationState,
|
|
18
|
+
getPathFilenameFoldsTotal,
|
|
19
|
+
outfitCountFolds,
|
|
20
|
+
saveFoldsTotal,
|
|
21
|
+
saveFoldsTotalFAILearly,
|
|
22
|
+
setProcessorLimit,
|
|
23
|
+
The,
|
|
24
|
+
validateListDimensions,
|
|
25
|
+
)
|
|
19
26
|
from os import PathLike
|
|
20
27
|
from pathlib import PurePath
|
|
21
28
|
|
|
@@ -24,18 +31,27 @@ def countFolds(listDimensions: Sequence[int]
|
|
|
24
31
|
, computationDivisions: int | str | None = None
|
|
25
32
|
, CPUlimit: int | float | bool | None = None
|
|
26
33
|
) -> int:
|
|
27
|
-
"""
|
|
34
|
+
"""
|
|
35
|
+
Count the total number of possible foldings for a given map dimensions.
|
|
36
|
+
|
|
37
|
+
This function serves as the main public interface to the map folding algorithm,
|
|
38
|
+
handling all parameter validation, computation state management, and result
|
|
39
|
+
persistence in a user-friendly way.
|
|
28
40
|
|
|
29
|
-
Parameters
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
listDimensions: List of integers representing the dimensions of the map to be folded.
|
|
44
|
+
pathLikeWriteFoldsTotal (None): Path, filename, or pathFilename to write the total fold count to.
|
|
45
|
+
If a directory is provided, creates a file with a default name based on map dimensions.
|
|
46
|
+
computationDivisions (None):
|
|
47
|
+
Whether and how to divide the computational work. See notes for details.
|
|
48
|
+
CPUlimit (None): This is only relevant if there are `computationDivisions`: whether and how to limit the CPU usage. See notes for details.
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
foldsTotal: Total number of distinct ways to fold a map of the given dimensions.
|
|
38
52
|
|
|
53
|
+
Notes
|
|
54
|
+
-----
|
|
39
55
|
Computation divisions:
|
|
40
56
|
- None: no division of the computation into tasks; sets task divisions to 0
|
|
41
57
|
- int: direct set the number of task divisions; cannot exceed the map's total leaves
|
|
@@ -51,7 +67,8 @@ def countFolds(listDimensions: Sequence[int]
|
|
|
51
67
|
- Integer `<= -1`: Subtract the absolute value from total CPUs.
|
|
52
68
|
|
|
53
69
|
N.B.: You probably don't want to divide the computation into tasks.
|
|
54
|
-
|
|
70
|
+
|
|
71
|
+
If you want to compute a large `foldsTotal`, dividing the computation into tasks is usually a bad idea. Dividing the algorithm into tasks is inherently inefficient: efficient division into tasks means there would be no overlap in the work performed by each task. When dividing this algorithm, the amount of overlap is between 50% and 90% by all tasks: at least 50% of the work done by every task must be done by _all_ tasks. If you improve the computation time, it will only change by -10 to -50% depending on (at the very least) the ratio of the map dimensions and the number of leaves. If an undivided computation would take 10 hours on your computer, for example, the computation will still take at least 5 hours but you might reduce the time to 9 hours. Most of the time, however, you will increase the computation time. If logicalCores >= leavesTotal, it will probably be faster. If logicalCores <= 2 * leavesTotal, it will almost certainly be slower for all map dimensions.
|
|
55
72
|
"""
|
|
56
73
|
mapShape: tuple[int, ...] = validateListDimensions(listDimensions)
|
|
57
74
|
concurrencyLimit: int = setProcessorLimit(CPUlimit, The.concurrencyPackage)
|
|
@@ -63,9 +80,7 @@ def countFolds(listDimensions: Sequence[int]
|
|
|
63
80
|
else:
|
|
64
81
|
pathFilenameFoldsTotal = None
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
computationStateComplete: ComputationState = dispatcherCallableProxy(computationStateInitialized)
|
|
68
|
-
# computationStateComplete: ComputationState = The.dispatcher(computationStateInitialized)
|
|
83
|
+
computationStateComplete: ComputationState = The.dispatcher(computationStateInitialized)
|
|
69
84
|
|
|
70
85
|
computationStateComplete.getFoldsTotal()
|
|
71
86
|
|
|
@@ -19,7 +19,7 @@ These utilities form a stable internal API that other modules depend on, particu
|
|
|
19
19
|
produce optimized implementations.
|
|
20
20
|
"""
|
|
21
21
|
from collections.abc import Sequence
|
|
22
|
-
from mapFolding
|
|
22
|
+
from mapFolding import ComputationState, NumPyIntegerType
|
|
23
23
|
from numpy import dtype as numpy_dtype, int64 as numpy_int64, ndarray
|
|
24
24
|
from sys import maxsize as sysMaxsize
|
|
25
25
|
from typing import Any
|
|
@@ -165,7 +165,7 @@ def _makeConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int) -> ndarray
|
|
|
165
165
|
connectionGraph[indexDimension, activeLeaf1ndex, connectee1ndex] = connectee1ndex + cumulativeProduct[indexDimension]
|
|
166
166
|
return connectionGraph
|
|
167
167
|
|
|
168
|
-
def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: type[
|
|
168
|
+
def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: type[NumPyIntegerType]) -> ndarray[tuple[int, int, int], numpy_dtype[NumPyIntegerType]]:
|
|
169
169
|
"""
|
|
170
170
|
Create a properly typed connection graph for the map folding algorithm.
|
|
171
171
|
|
|
@@ -193,7 +193,7 @@ def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: ty
|
|
|
193
193
|
connectionGraph = connectionGraph.astype(datatype)
|
|
194
194
|
return connectionGraph
|
|
195
195
|
|
|
196
|
-
def makeDataContainer(shape: int | tuple[int, ...], datatype: type[
|
|
196
|
+
def makeDataContainer(shape: int | tuple[int, ...], datatype: type[NumPyIntegerType]) -> ndarray[Any, numpy_dtype[NumPyIntegerType]]:
|
|
197
197
|
"""
|
|
198
198
|
Create a typed NumPy array container with initialized values.
|
|
199
199
|
|
|
@@ -331,8 +331,7 @@ def validateListDimensions(listDimensions: Sequence[int]) -> tuple[int, ...]:
|
|
|
331
331
|
ValueError
|
|
332
332
|
If the input is empty or contains negative values.
|
|
333
333
|
NotImplementedError
|
|
334
|
-
If fewer than two positive dimensions are provided
|
|
335
|
-
represent a valid map folding problem.
|
|
334
|
+
If fewer than two positive dimensions are provided.
|
|
336
335
|
"""
|
|
337
336
|
if not listDimensions:
|
|
338
337
|
raise ValueError("`listDimensions` is a required parameter.")
|
|
@@ -22,8 +22,7 @@ implementation in the package.
|
|
|
22
22
|
from collections.abc import Callable
|
|
23
23
|
from datetime import datetime, timedelta
|
|
24
24
|
from functools import cache
|
|
25
|
-
from mapFolding
|
|
26
|
-
from mapFolding.toolboxFilesystem import writeStringToHere
|
|
25
|
+
from mapFolding import writeStringToHere, The
|
|
27
26
|
from pathlib import Path
|
|
28
27
|
from typing import Any, Final, TYPE_CHECKING
|
|
29
28
|
import argparse
|
|
@@ -60,14 +59,20 @@ class SettingsOEIShardcodedValues(TypedDict):
|
|
|
60
59
|
valuesTestValidation: list[int]
|
|
61
60
|
|
|
62
61
|
settingsOEIShardcodedValues: dict[str, SettingsOEIShardcodedValues] = {
|
|
62
|
+
'A000136': {
|
|
63
|
+
'getMapShape': lambda n: tuple(sorted([1, n])),
|
|
64
|
+
'valuesBenchmark': [14],
|
|
65
|
+
'valuesTestParallelization': [*range(3, 7)],
|
|
66
|
+
'valuesTestValidation': [random.randint(2, 9)],
|
|
67
|
+
},
|
|
63
68
|
'A001415': {
|
|
64
|
-
'getMapShape': lambda n: (2, n)
|
|
69
|
+
'getMapShape': lambda n: tuple(sorted([2, n])),
|
|
65
70
|
'valuesBenchmark': [14],
|
|
66
71
|
'valuesTestParallelization': [*range(3, 7)],
|
|
67
72
|
'valuesTestValidation': [random.randint(2, 9)],
|
|
68
73
|
},
|
|
69
74
|
'A001416': {
|
|
70
|
-
'getMapShape': lambda n: (3, n)
|
|
75
|
+
'getMapShape': lambda n: tuple(sorted([3, n])),
|
|
71
76
|
'valuesBenchmark': [9],
|
|
72
77
|
'valuesTestParallelization': [*range(3, 5)],
|
|
73
78
|
'valuesTestValidation': [random.randint(2, 6)],
|
|
@@ -149,9 +154,9 @@ def _parseBFileOEIS(OEISbFile: str, oeisID: str) -> dict[int, int]:
|
|
|
149
154
|
sequence ID or if the content format is invalid.
|
|
150
155
|
"""
|
|
151
156
|
bFileLines: list[str] = OEISbFile.strip().splitlines()
|
|
152
|
-
if not bFileLines.pop(0).startswith(f"# {oeisID}"):
|
|
153
|
-
|
|
154
|
-
|
|
157
|
+
# if not bFileLines.pop(0).startswith(f"# {oeisID}"):
|
|
158
|
+
# warnings.warn(f"Content does not match sequence {oeisID}")
|
|
159
|
+
# return {-1: -1}
|
|
155
160
|
|
|
156
161
|
OEISsequence: dict[int, int] = {}
|
|
157
162
|
for line in bFileLines:
|
|
@@ -162,6 +167,27 @@ def _parseBFileOEIS(OEISbFile: str, oeisID: str) -> dict[int, int]:
|
|
|
162
167
|
return OEISsequence
|
|
163
168
|
|
|
164
169
|
def getOEISofficial(pathFilenameCache: Path, url: str) -> None | str:
|
|
170
|
+
"""
|
|
171
|
+
Retrieve OEIS sequence data from cache or online source.
|
|
172
|
+
|
|
173
|
+
This function implements a caching strategy for OEIS sequence data, first checking
|
|
174
|
+
if a local cached copy exists and is not expired. If a valid cache exists, it returns
|
|
175
|
+
the cached content; otherwise, it fetches the data from the OEIS website and
|
|
176
|
+
writes it to the cache for future use.
|
|
177
|
+
|
|
178
|
+
Parameters:
|
|
179
|
+
pathFilenameCache: Path to the local cache file.
|
|
180
|
+
url: URL to retrieve the OEIS sequence data from if cache is invalid or missing.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
oeisInformation: The retrieved OEIS sequence information as a string, or None if
|
|
184
|
+
the information could not be retrieved.
|
|
185
|
+
|
|
186
|
+
Notes:
|
|
187
|
+
The cache expiration period is controlled by the global `cacheDays` variable.
|
|
188
|
+
If the function fails to retrieve data from both cache and online source,
|
|
189
|
+
it will return None and issue a warning.
|
|
190
|
+
"""
|
|
165
191
|
tryCache: bool = False
|
|
166
192
|
if pathFilenameCache.exists():
|
|
167
193
|
fileAge: timedelta = datetime.now() - datetime.fromtimestamp(pathFilenameCache.stat().st_mtime)
|
|
@@ -175,6 +201,7 @@ def getOEISofficial(pathFilenameCache: Path, url: str) -> None | str:
|
|
|
175
201
|
tryCache = False
|
|
176
202
|
|
|
177
203
|
if not tryCache:
|
|
204
|
+
# Change http handling #13
|
|
178
205
|
httpResponse: urllib.response.addinfourl = urllib.request.urlopen(url)
|
|
179
206
|
oeisInformation = httpResponse.read().decode('utf-8')
|
|
180
207
|
writeStringToHere(oeisInformation, pathFilenameCache)
|
|
@@ -214,6 +241,27 @@ def getOEISidValues(oeisID: str) -> dict[int, int]:
|
|
|
214
241
|
return {-1: -1}
|
|
215
242
|
|
|
216
243
|
def getOEISidInformation(oeisID: str) -> tuple[str, int]:
|
|
244
|
+
"""
|
|
245
|
+
Retrieve the description and offset for an OEIS sequence.
|
|
246
|
+
|
|
247
|
+
This function fetches the metadata for a given OEIS sequence ID, including
|
|
248
|
+
its textual description and index offset value. It uses a caching mechanism
|
|
249
|
+
to avoid redundant network requests while ensuring data freshness.
|
|
250
|
+
|
|
251
|
+
Parameters:
|
|
252
|
+
oeisID: The OEIS sequence identifier to retrieve information for.
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
A tuple containing:
|
|
256
|
+
- description: A string describing the sequence's mathematical meaning.
|
|
257
|
+
- offset: An integer representing the starting index of the sequence.
|
|
258
|
+
Usually 0 or 1, depending on the mathematical context.
|
|
259
|
+
|
|
260
|
+
Notes:
|
|
261
|
+
Sequence descriptions are parsed from the machine-readable format of OEIS.
|
|
262
|
+
If information cannot be retrieved, warning messages are issued and
|
|
263
|
+
fallback values are returned.
|
|
264
|
+
"""
|
|
217
265
|
oeisID = validateOEISid(oeisID)
|
|
218
266
|
pathFilenameCache: Path = pathCache / f"{oeisID}.txt"
|
|
219
267
|
url: str = f"https://oeis.org/search?q=id:{oeisID}&fmt=text"
|
|
@@ -243,6 +291,26 @@ def getOEISidInformation(oeisID: str) -> tuple[str, int]:
|
|
|
243
291
|
return description, offset
|
|
244
292
|
|
|
245
293
|
def makeSettingsOEIS() -> dict[str, SettingsOEIS]:
|
|
294
|
+
"""
|
|
295
|
+
Construct the comprehensive settings dictionary for all implemented OEIS sequences.
|
|
296
|
+
|
|
297
|
+
This function builds a complete configuration dictionary for all supported OEIS
|
|
298
|
+
sequences by retrieving and combining:
|
|
299
|
+
1. Sequence values from OEIS b-files
|
|
300
|
+
2. Sequence metadata (descriptions and offsets)
|
|
301
|
+
3. Hardcoded mapping functions and test values
|
|
302
|
+
|
|
303
|
+
The resulting dictionary provides a single authoritative source for all OEIS-related
|
|
304
|
+
configurations used throughout the package, including:
|
|
305
|
+
- Mathematical descriptions of each sequence
|
|
306
|
+
- Functions to convert between sequence indices and map dimensions
|
|
307
|
+
- Known sequence values retrieved from OEIS
|
|
308
|
+
- Testing and benchmarking reference values
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
A dictionary mapping OEIS sequence IDs to their complete settings objects,
|
|
312
|
+
containing all metadata and known values needed for computation and validation.
|
|
313
|
+
"""
|
|
246
314
|
settingsTarget: dict[str, SettingsOEIS] = {}
|
|
247
315
|
for oeisID in oeisIDsImplemented:
|
|
248
316
|
valuesKnownSherpa: dict[int, int] = getOEISidValues(oeisID)
|
|
@@ -277,6 +345,25 @@ def makeDictionaryFoldsTotalKnown() -> dict[tuple[int, ...], int]:
|
|
|
277
345
|
return dictionaryMapDimensionsToFoldsTotalKnown
|
|
278
346
|
|
|
279
347
|
def getFoldsTotalKnown(mapShape: tuple[int, ...]) -> int:
|
|
348
|
+
"""
|
|
349
|
+
Retrieve the known total number of foldings for a given map shape.
|
|
350
|
+
|
|
351
|
+
This function looks up precalculated folding totals for specific map dimensions
|
|
352
|
+
from OEIS sequences. It serves as a rapid reference for known values without
|
|
353
|
+
requiring computation, and can be used to validate algorithm results.
|
|
354
|
+
|
|
355
|
+
Parameters:
|
|
356
|
+
mapShape: A tuple of integers representing the dimensions of the map.
|
|
357
|
+
|
|
358
|
+
Returns:
|
|
359
|
+
foldingsTotal: The known total number of foldings for the given map shape,
|
|
360
|
+
or -1 if the map shape doesn't match any known values in the OEIS sequences.
|
|
361
|
+
|
|
362
|
+
Notes:
|
|
363
|
+
The function uses a cached dictionary (via makeDictionaryFoldsTotalKnown) to
|
|
364
|
+
efficiently retrieve values without repeatedly parsing OEIS data. Map shape
|
|
365
|
+
tuples are sorted internally to ensure consistent lookup regardless of dimension order.
|
|
366
|
+
"""
|
|
280
367
|
lookupFoldsTotal = makeDictionaryFoldsTotalKnown()
|
|
281
368
|
return lookupFoldsTotal.get(tuple(mapShape), -1)
|
|
282
369
|
|