mapFolding 0.8.0__tar.gz → 0.8.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.
Files changed (53) hide show
  1. {mapfolding-0.8.0 → mapfolding-0.8.1}/PKG-INFO +50 -44
  2. {mapfolding-0.8.0 → mapfolding-0.8.1}/README.md +41 -38
  3. mapfolding-0.8.1/mapFolding/__init__.py +38 -0
  4. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/basecamp.py +14 -0
  5. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/beDRY.py +16 -1
  6. mapfolding-0.8.1/mapFolding/filesystem.py +129 -0
  7. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/noHomeYet.py +12 -0
  8. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/oeis.py +16 -1
  9. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/flattened.py +46 -45
  10. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/hunterNumba.py +4 -4
  11. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/irvineJavaPort.py +1 -1
  12. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/lunnanNumpy.py +3 -4
  13. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/lunnanWhile.py +5 -7
  14. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/rotatedEntryPoint.py +2 -3
  15. mapfolding-0.8.1/mapFolding/someAssemblyRequired/__init__.py +46 -0
  16. mapfolding-0.8.1/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +38 -0
  17. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/someAssemblyRequired/ingredientsNumba.py +22 -1
  18. mapfolding-0.8.1/mapFolding/someAssemblyRequired/synthesizeNumbaFlow.py +196 -0
  19. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/someAssemblyRequired/synthesizeNumbaJobVESTIGIAL.py +3 -4
  20. mapfolding-0.8.1/mapFolding/someAssemblyRequired/transformDataStructures.py +162 -0
  21. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/someAssemblyRequired/transformationTools.py +216 -199
  22. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/theDao.py +19 -5
  23. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/theSSOT.py +19 -1
  24. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/PKG-INFO +50 -44
  25. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/SOURCES.txt +3 -5
  26. {mapfolding-0.8.0 → mapfolding-0.8.1}/pyproject.toml +21 -14
  27. mapfolding-0.8.1/tests/__init__.py +0 -0
  28. mapfolding-0.8.0/mapFolding/__init__.py +0 -9
  29. mapfolding-0.8.0/mapFolding/filesystem.py +0 -95
  30. mapfolding-0.8.0/mapFolding/reference/lunnan.py +0 -153
  31. mapfolding-0.8.0/mapFolding/someAssemblyRequired/Z0Z_workbench.py +0 -350
  32. mapfolding-0.8.0/mapFolding/someAssemblyRequired/__init__.py +0 -17
  33. mapfolding-0.8.0/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -20
  34. mapfolding-0.8.0/mapFolding/someAssemblyRequired/synthesizeDataConverters.py +0 -117
  35. mapfolding-0.8.0/mapFolding/syntheticModules/numbaCountHistoricalExample.py +0 -158
  36. mapfolding-0.8.0/mapFolding/syntheticModules/numba_doTheNeedfulHistoricalExample.py +0 -13
  37. {mapfolding-0.8.0 → mapfolding-0.8.1}/LICENSE +0 -0
  38. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/py.typed +0 -0
  39. {mapfolding-0.8.0/tests → mapfolding-0.8.1/mapFolding/reference}/__init__.py +0 -0
  40. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/jax.py +0 -0
  41. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
  42. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding/syntheticModules/numbaCount_doTheNeedful.py +0 -0
  43. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/dependency_links.txt +0 -0
  44. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/entry_points.txt +0 -0
  45. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/requires.txt +0 -0
  46. {mapfolding-0.8.0 → mapfolding-0.8.1}/mapFolding.egg-info/top_level.txt +0 -0
  47. {mapfolding-0.8.0 → mapfolding-0.8.1}/setup.cfg +0 -0
  48. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/conftest.py +0 -0
  49. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/test_computations.py +0 -0
  50. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/test_filesystem.py +0 -0
  51. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/test_oeis.py +0 -0
  52. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/test_other.py +0 -0
  53. {mapfolding-0.8.0 → mapfolding-0.8.1}/tests/test_tasks.py +0 -0
@@ -1,18 +1,17 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: mapFolding
3
- Version: 0.8.0
4
- Summary: Count distinct ways to fold a map (or a strip of stamps)
3
+ Version: 0.8.1
4
+ Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
5
5
  Author-email: Hunter Hogan <HunterHogan@pm.me>
6
6
  License: CC-BY-NC-4.0
7
7
  Project-URL: Donate, https://www.patreon.com/integrated
8
8
  Project-URL: Homepage, https://github.com/hunterhogan/mapFolding
9
9
  Project-URL: Repository, https://github.com/hunterhogan/mapFolding.git
10
- Keywords: A001415,A001416,A001417,A001418,A195646,combinatorics,folding,map folding,OEIS,optimization,stamp folding
10
+ 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
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
13
14
  Classifier: Intended Audience :: Education
14
- Classifier: Intended Audience :: End Users/Desktop
15
- Classifier: Intended Audience :: Other Audience
16
15
  Classifier: Intended Audience :: Science/Research
17
16
  Classifier: Natural Language :: English
18
17
  Classifier: Operating System :: OS Independent
@@ -23,7 +22,10 @@ Classifier: Programming Language :: Python :: 3.11
23
22
  Classifier: Programming Language :: Python :: 3.12
24
23
  Classifier: Programming Language :: Python :: 3.13
25
24
  Classifier: Topic :: Scientific/Engineering :: Mathematics
25
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
26
+ Classifier: Topic :: Software Development :: Code Generators
26
27
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
+ Classifier: Topic :: Software Development :: Compilers
27
29
  Classifier: Typing :: Typed
28
30
  Requires-Python: >=3.10
29
31
  Description-Content-Type: text/markdown
@@ -43,6 +45,7 @@ Requires-Dist: pytest-cov; extra == "testing"
43
45
  Requires-Dist: pytest-env; extra == "testing"
44
46
  Requires-Dist: pytest-xdist; extra == "testing"
45
47
  Requires-Dist: pyupgrade; extra == "testing"
48
+ Dynamic: license-file
46
49
 
47
50
  # mapFolding: Algorithms for enumerating distinct map/stamp folding patterns 🗺️
48
51
 
@@ -51,8 +54,6 @@ Requires-Dist: pyupgrade; extra == "testing"
51
54
  [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
52
55
  ![Static Badge](https://img.shields.io/badge/issues-I%20have%20them-brightgreen)
53
56
  [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-3b434b)](https://creativecommons.org/licenses/by-nc/4.0/)
54
- ![PyPI - Downloads](https://img.shields.io/pypi/dd/mapFolding)
55
- ![GitHub repo size](https://img.shields.io/github/repo-size/hunterhogan/mapFolding)
56
57
 
57
58
  ---
58
59
 
@@ -100,44 +101,49 @@ Available OEIS sequences:
100
101
 
101
102
  ### 2. **Algorithm Zoo** 🦒
102
103
 
103
- - **Lunnons 1971 Algorithm**: A painstakingly debugged version of [the original typo-riddled code](https://github.com/hunterhogan/mapFolding/blob/mapFolding/reference/foldings.txt)
104
+ - **Lunnon's 1971 Algorithm**: A painstakingly debugged version of [the original typo-riddled code](https://github.com/hunterhogan/mapFolding/blob/mapFolding/reference/foldings.txt)
104
105
  - The /reference directory.
105
106
  - **Numba-JIT Accelerated**: Up to 1000× faster than pure Python ([benchmarks](https://github.com/hunterhogan/mapFolding/blob/mapFolding/notes/Speed%20highlights.md))
106
107
 
107
- ### 3. **For Researchers** 🔬
108
-
109
- - Change multiple minute settings, such as the bit width of the data types.
110
- - Transform the algorithm using AST
111
- - Create hyper-optimized modules to compute a specific map.
112
-
113
- ### 4. **Customizing your algorithm**
114
-
115
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\synthesizeNumbaJob.py (and/or synthesizeNumba____.py, as applicable)~~
116
- - Synthesize a Numba-optimized module for a specific mapShape
117
- - Synthesize _from_ a module in mapFolding\syntheticModules or from any source you select
118
- - Use the existing transformation options
119
- - Or create new ways of transforming the algorithm from its source to a specific job
120
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\makeJob.py~~
121
- - Initialize data for a specific mapShape
122
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\synthesizeNumbaModules.py (and/or synthesizeNumba____.py, as applicable)~~
123
- - Synthesize one or more Numba-optimized modules for parallel or sequential computation
124
- - Overwrite the modules in mapFolding\syntheticModules or save the module(s) to a custom path
125
- - Synthesize _from_ the algorithm(s) in mapFolding\theDao.py or from any source you select
126
- - Use the existing transformation options
127
- - Or create new ways of transforming the algorithm from its source to a new module
128
- - Use your new module in synthesizeNumbaJob.py, above, as the source to create a mapShape-specific job module
129
- - mapFolding\theDao.py
130
- - Modify the algorithms for initializing values, parallel computation, and/or sequential computation
131
- - Use the modified algorithm(s) in synthesizeNumbaModules.py, above, to create Numba-optimized version(s)
132
- - Then use a Numba-optimized version in synthesizeNumbaJob.py, above, to create a hyper-optimized version for a specific mapShape
133
- - mapFolding\theSSOT.py
134
- - Modify broad settings or find functions to modify broad settings, such as data structures and their data types
135
- - Create new settings or groups of settings
136
- - mapFolding\beDRY.py
137
- - Functions to handle common tasks, such as parsing parameters or creating the `connectionGraph` for a mapShape (a Cartesian product decomposition)
138
- - mapFolding\someAssemblyRequired
139
- - Create new transformations to optimize the algorithm, such as for JAX, CuPy, or CUDA
140
- - (mapFolding\reference\jax.py has a once-functional JAX implementation, and synthesizeModuleJAX.py might be a useful starting point)
108
+ ### 3. **For Researchers and Power Users** 🔬
109
+
110
+ This package provides a sophisticated code transformation framework that can turn readable algorithm implementations into highly-optimized computational engines:
111
+
112
+ - **Algorithmic Exploration**: Study the core algorithm in `theDao.py`, which uses a functional state-transformation approach with clear, isolated functions
113
+ - **Performance Optimization**: Generate specialized implementations with the `someAssemblyRequired` transformation pipeline:
114
+ - AST-based code analysis and manipulation
115
+ - Dataclass "shattering" to decompose complex state objects into primitive components
116
+ - Just-in-time compilation with Numba and various optimization profiles
117
+ - LLVM IR extraction for low-level algorithmic analysis
118
+
119
+ - **Extensible Design**: The transformation framework is abstract and generic, enabling:
120
+ - Creation of new optimization targets beyond the included Numba implementation
121
+ - Customization of compilation parameters and optimization levels
122
+ - Development of specialized algorithms for specific map dimensions
123
+
124
+ ### 4. **Customization and Extension Guide**
125
+
126
+ The package architecture supports multiple levels of customization:
127
+
128
+ - **Basic Usage**: Work with the high-level API in `basecamp.py` for standard computations
129
+ - **Algorithm Modification**:
130
+ - Modify the core algorithm in `theDao.py` while preserving its functional approach
131
+ - Configure system-wide settings in `theSSOT.py` to adjust data types and performance characteristics
132
+ - Use utility functions in `beDRY.py` for common operations
133
+
134
+ - **Advanced Transformation**:
135
+ - The `someAssemblyRequired` package provides tools to transform code at the AST level:
136
+ - `transformationTools.py` contains utilities for AST manipulation and code generation
137
+ - `transformDataStructures.py` handles complex data structure transformations
138
+ - `ingredientsNumba.py` provides Numba-specific configuration profiles
139
+ - `synthesizeNumbaFlow.py` orchestrates the transformation process
140
+
141
+ - **Custom Deployment**:
142
+ - Generate specialized implementations for specific dimensions
143
+ - Create optimized modules that can be executed as standalone scripts
144
+ - Extract LLVM IR for further analysis or optimization
145
+
146
+ The package's multi-level design allows you to start with simple API calls and progressively delve deeper into optimization as your computational needs grow.
141
147
 
142
148
  ## Map-folding Video
143
149
 
@@ -154,4 +160,4 @@ Available OEIS sequences:
154
160
  [![Static Badge](https://img.shields.io/badge/2011_August-Homeless_since-blue?style=flat)](https://HunterThinks.com/support)
155
161
  [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UC3Gx7kz61009NbhpRtPP7tw)](https://www.youtube.com/@HunterHogan)
156
162
 
157
- [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.png)](https://creativecommons.org/licenses/by-nc/4.0/)
163
+ [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
@@ -5,8 +5,6 @@
5
5
  [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
6
6
  ![Static Badge](https://img.shields.io/badge/issues-I%20have%20them-brightgreen)
7
7
  [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-3b434b)](https://creativecommons.org/licenses/by-nc/4.0/)
8
- ![PyPI - Downloads](https://img.shields.io/pypi/dd/mapFolding)
9
- ![GitHub repo size](https://img.shields.io/github/repo-size/hunterhogan/mapFolding)
10
8
 
11
9
  ---
12
10
 
@@ -54,44 +52,49 @@ Available OEIS sequences:
54
52
 
55
53
  ### 2. **Algorithm Zoo** 🦒
56
54
 
57
- - **Lunnons 1971 Algorithm**: A painstakingly debugged version of [the original typo-riddled code](https://github.com/hunterhogan/mapFolding/blob/mapFolding/reference/foldings.txt)
55
+ - **Lunnon's 1971 Algorithm**: A painstakingly debugged version of [the original typo-riddled code](https://github.com/hunterhogan/mapFolding/blob/mapFolding/reference/foldings.txt)
58
56
  - The /reference directory.
59
57
  - **Numba-JIT Accelerated**: Up to 1000× faster than pure Python ([benchmarks](https://github.com/hunterhogan/mapFolding/blob/mapFolding/notes/Speed%20highlights.md))
60
58
 
61
- ### 3. **For Researchers** 🔬
62
-
63
- - Change multiple minute settings, such as the bit width of the data types.
64
- - Transform the algorithm using AST
65
- - Create hyper-optimized modules to compute a specific map.
66
-
67
- ### 4. **Customizing your algorithm**
68
-
69
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\synthesizeNumbaJob.py (and/or synthesizeNumba____.py, as applicable)~~
70
- - Synthesize a Numba-optimized module for a specific mapShape
71
- - Synthesize _from_ a module in mapFolding\syntheticModules or from any source you select
72
- - Use the existing transformation options
73
- - Or create new ways of transforming the algorithm from its source to a specific job
74
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\makeJob.py~~
75
- - Initialize data for a specific mapShape
76
- - Renovations in progress: ~~mapFolding\someAssemblyRequired\synthesizeNumbaModules.py (and/or synthesizeNumba____.py, as applicable)~~
77
- - Synthesize one or more Numba-optimized modules for parallel or sequential computation
78
- - Overwrite the modules in mapFolding\syntheticModules or save the module(s) to a custom path
79
- - Synthesize _from_ the algorithm(s) in mapFolding\theDao.py or from any source you select
80
- - Use the existing transformation options
81
- - Or create new ways of transforming the algorithm from its source to a new module
82
- - Use your new module in synthesizeNumbaJob.py, above, as the source to create a mapShape-specific job module
83
- - mapFolding\theDao.py
84
- - Modify the algorithms for initializing values, parallel computation, and/or sequential computation
85
- - Use the modified algorithm(s) in synthesizeNumbaModules.py, above, to create Numba-optimized version(s)
86
- - Then use a Numba-optimized version in synthesizeNumbaJob.py, above, to create a hyper-optimized version for a specific mapShape
87
- - mapFolding\theSSOT.py
88
- - Modify broad settings or find functions to modify broad settings, such as data structures and their data types
89
- - Create new settings or groups of settings
90
- - mapFolding\beDRY.py
91
- - Functions to handle common tasks, such as parsing parameters or creating the `connectionGraph` for a mapShape (a Cartesian product decomposition)
92
- - mapFolding\someAssemblyRequired
93
- - Create new transformations to optimize the algorithm, such as for JAX, CuPy, or CUDA
94
- - (mapFolding\reference\jax.py has a once-functional JAX implementation, and synthesizeModuleJAX.py might be a useful starting point)
59
+ ### 3. **For Researchers and Power Users** 🔬
60
+
61
+ This package provides a sophisticated code transformation framework that can turn readable algorithm implementations into highly-optimized computational engines:
62
+
63
+ - **Algorithmic Exploration**: Study the core algorithm in `theDao.py`, which uses a functional state-transformation approach with clear, isolated functions
64
+ - **Performance Optimization**: Generate specialized implementations with the `someAssemblyRequired` transformation pipeline:
65
+ - AST-based code analysis and manipulation
66
+ - Dataclass "shattering" to decompose complex state objects into primitive components
67
+ - Just-in-time compilation with Numba and various optimization profiles
68
+ - LLVM IR extraction for low-level algorithmic analysis
69
+
70
+ - **Extensible Design**: The transformation framework is abstract and generic, enabling:
71
+ - Creation of new optimization targets beyond the included Numba implementation
72
+ - Customization of compilation parameters and optimization levels
73
+ - Development of specialized algorithms for specific map dimensions
74
+
75
+ ### 4. **Customization and Extension Guide**
76
+
77
+ The package architecture supports multiple levels of customization:
78
+
79
+ - **Basic Usage**: Work with the high-level API in `basecamp.py` for standard computations
80
+ - **Algorithm Modification**:
81
+ - Modify the core algorithm in `theDao.py` while preserving its functional approach
82
+ - Configure system-wide settings in `theSSOT.py` to adjust data types and performance characteristics
83
+ - Use utility functions in `beDRY.py` for common operations
84
+
85
+ - **Advanced Transformation**:
86
+ - The `someAssemblyRequired` package provides tools to transform code at the AST level:
87
+ - `transformationTools.py` contains utilities for AST manipulation and code generation
88
+ - `transformDataStructures.py` handles complex data structure transformations
89
+ - `ingredientsNumba.py` provides Numba-specific configuration profiles
90
+ - `synthesizeNumbaFlow.py` orchestrates the transformation process
91
+
92
+ - **Custom Deployment**:
93
+ - Generate specialized implementations for specific dimensions
94
+ - Create optimized modules that can be executed as standalone scripts
95
+ - Extract LLVM IR for further analysis or optimization
96
+
97
+ The package's multi-level design allows you to start with simple API calls and progressively delve deeper into optimization as your computational needs grow.
95
98
 
96
99
  ## Map-folding Video
97
100
 
@@ -108,4 +111,4 @@ Available OEIS sequences:
108
111
  [![Static Badge](https://img.shields.io/badge/2011_August-Homeless_since-blue?style=flat)](https://HunterThinks.com/support)
109
112
  [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UC3Gx7kz61009NbhpRtPP7tw)](https://www.youtube.com/@HunterHogan)
110
113
 
111
- [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.png)](https://creativecommons.org/licenses/by-nc/4.0/)
114
+ [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
@@ -0,0 +1,38 @@
1
+ """
2
+ Map folding enumeration and counting algorithms with optimization capabilities.
3
+
4
+ This package implements algorithms to count and enumerate the various 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 low-level 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: Utility functions for common operations and parameter management
14
+ - theSSOT: Single Source of Truth for configuration, types, and state management
15
+ - oeis: Interface to the Online Encyclopedia of Integer Sequences for known results
16
+
17
+ Extended functionality:
18
+ - someAssemblyRequired: Code transformation framework that optimizes the core algorithm
19
+ through AST manipulation, dataclass transformation, and compilation techniques
20
+
21
+ Special directories:
22
+ - .cache/: Stores cached data from external sources like OEIS to improve performance
23
+ - syntheticModules/: Contains dynamically generated, optimized implementations of the
24
+ core algorithm created by the code transformation framework
25
+
26
+ This package strives to balance algorithm readability and understandability with
27
+ high-performance computation capabilities, allowing users to compute map folding
28
+ totals for larger dimensions than previously feasible.
29
+ """
30
+ from mapFolding.basecamp import countFolds as countFolds
31
+ from mapFolding.oeis import clearOEIScache, getOEISids, OEIS_for_n
32
+
33
+ __all__ = [
34
+ 'clearOEIScache',
35
+ 'countFolds',
36
+ 'getOEISids',
37
+ 'OEIS_for_n',
38
+ ]
@@ -1,3 +1,17 @@
1
+ """
2
+ Public API for the map folding algorithm with simplified interface.
3
+
4
+ This module provides the main entry point for users of the mapFolding package,
5
+ abstracting away the complexities of the computational algorithm. It offers
6
+ a high-level interface to count the total number of possible ways to fold
7
+ a rectangular map of specified dimensions, with options for customizing the
8
+ computation process and saving results.
9
+
10
+ The primary function is countFolds, which handles parameter validation,
11
+ computation state management, dispatching to the appropriate algorithm
12
+ implementation, and optional persistence of results.
13
+ """
14
+
1
15
  from collections.abc import Sequence
2
16
  from mapFolding.beDRY import outfitCountFolds, setCPUlimit, validateListDimensions
3
17
  from mapFolding.filesystem import getPathFilenameFoldsTotal, saveFoldsTotal
@@ -1,4 +1,19 @@
1
- """A relatively stable API for oft-needed functionality."""
1
+ """
2
+ Utility functions for maintaining DRY (Don't Repeat Yourself) principles in the mapFolding package.
3
+
4
+ This module provides a collection of helper functions that abstract common operations needed
5
+ throughout the package, preventing code duplication and ensuring consistency. The functions
6
+ manage core aspects of the computation process, including:
7
+
8
+ 1. Resource allocation and system limits management
9
+ 2. Data structure initialization and manipulation
10
+ 3. Parameter validation and interpretation
11
+ 4. Construction of specialized arrays and matrices for the folding algorithm
12
+
13
+ The functions in this module serve as a relatively stable API for other modules to use,
14
+ particularly for initializing computation state, validating inputs, and creating data
15
+ structures needed by the folding algorithms.
16
+ """
2
17
  from collections.abc import Sequence
3
18
  from mapFolding.theSSOT import Array3D, ComputationState, getDatatypePackage, getNumpyDtypeDefault
4
19
  from sys import maxsize as sysMaxsize
@@ -0,0 +1,129 @@
1
+ """
2
+ Filesystem utilities for managing map folding computation results.
3
+
4
+ This module provides functions for standardized handling of files related to the mapFolding
5
+ package, with a focus on saving, retrieving, and naming computation results. It implements
6
+ consistent naming conventions and path resolution strategies to ensure that:
7
+
8
+ 1. Computation results are stored in a predictable location
9
+ 2. Filenames follow a consistent pattern based on map dimensions
10
+ 3. Results can be reliably retrieved for future reference
11
+ 4. The system handles file operations safely with appropriate error handling
12
+
13
+ The module serves as the interface between the computational components of the package
14
+ and the filesystem, abstracting away the details of file operations and path management.
15
+ """
16
+ from pathlib import Path, PurePath
17
+ from typing import Any
18
+ from os import PathLike
19
+ import os
20
+
21
+ def getFilenameFoldsTotal(mapShape: tuple[int, ...]) -> str:
22
+ """
23
+ Create a standardized filename for a computed `foldsTotal` value.
24
+
25
+ This function generates a consistent, filesystem-safe filename based on map dimensions.
26
+ Standardizing filenames ensures that results can be reliably stored and retrieved,
27
+ avoiding potential filesystem incompatibilities or Python naming restrictions.
28
+
29
+ Parameters:
30
+ mapShape: A sequence of integers representing the dimensions of the map.
31
+
32
+ Returns:
33
+ filenameFoldsTotal: A filename string in format 'pMxN.foldsTotal' where M,N are sorted dimensions.
34
+
35
+ Notes:
36
+ The filename format ensures:
37
+ - No spaces in the filename
38
+ - Safe filesystem characters
39
+ - Unique extension (.foldsTotal)
40
+ - Python-safe strings (no starting with numbers, no reserved words)
41
+ - The 'p' prefix preserves compatibility with Lunnan's original code.
42
+ """
43
+ return 'p' + 'x'.join(str(dimension) for dimension in sorted(mapShape)) + '.foldsTotal'
44
+
45
+ def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal: str | PathLike[str] | None = None) -> Path:
46
+ """
47
+ Get a standardized path and filename for the computed foldsTotal value.
48
+
49
+ This function resolves paths for storing computation results, handling different
50
+ input types including directories, absolute paths, or relative paths. It ensures
51
+ that all parent directories exist in the resulting path.
52
+
53
+ Parameters:
54
+ mapShape: List of dimensions for the map folding problem.
55
+ pathLikeWriteFoldsTotal (getPathJobRootDEFAULT): Path, filename, or relative path and filename.
56
+ If None, uses default path. If a directory, appends standardized filename.
57
+
58
+ Returns:
59
+ pathFilenameFoldsTotal: Absolute path and filename for storing the foldsTotal value.
60
+
61
+ Notes:
62
+ The function creates any necessary directories in the path if they don't exist.
63
+ """
64
+ from mapFolding.theSSOT import getPathJobRootDEFAULT
65
+
66
+ if pathLikeWriteFoldsTotal is None:
67
+ pathFilenameFoldsTotal = getPathJobRootDEFAULT() / getFilenameFoldsTotal(mapShape)
68
+ else:
69
+ pathLikeSherpa = Path(pathLikeWriteFoldsTotal)
70
+ if pathLikeSherpa.is_dir():
71
+ pathFilenameFoldsTotal = pathLikeSherpa / getFilenameFoldsTotal(mapShape)
72
+ elif pathLikeSherpa.is_file() and pathLikeSherpa.is_absolute():
73
+ pathFilenameFoldsTotal = pathLikeSherpa
74
+ else:
75
+ pathFilenameFoldsTotal = getPathJobRootDEFAULT() / pathLikeSherpa
76
+
77
+ pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
78
+ return pathFilenameFoldsTotal
79
+
80
+ def saveFoldsTotal(pathFilename: str | PathLike[str], foldsTotal: int) -> None:
81
+ """
82
+ Save `foldsTotal` value to disk with multiple fallback mechanisms.
83
+
84
+ This function attempts to save the computed `foldsTotal` value to the specified
85
+ location, with backup strategies in case the primary save attempt fails.
86
+ The robustness is critical since these computations may take days to complete.
87
+
88
+ Parameters:
89
+ pathFilename: Target save location for the `foldsTotal` value
90
+ foldsTotal: The computed value to save
91
+
92
+ Notes:
93
+ If the primary save fails, the function will attempt alternative save methods:
94
+ 1. Print the value prominently to stdout
95
+ 2. Create a fallback file in the current working directory
96
+ 3. As a last resort, simply print the value
97
+ """
98
+ try:
99
+ pathFilenameFoldsTotal = Path(pathFilename)
100
+ pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
101
+ pathFilenameFoldsTotal.write_text(str(foldsTotal))
102
+ except Exception as ERRORmessage:
103
+ try:
104
+ print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal=}\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
105
+ print(ERRORmessage)
106
+ print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal=}\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
107
+ randomnessPlanB = (int(str(foldsTotal).strip()[-1]) + 1) * ['YO_']
108
+ filenameInfixUnique = ''.join(randomnessPlanB)
109
+ pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt')
110
+ writeStreamFallback = open(pathFilenamePlanB, 'w')
111
+ writeStreamFallback.write(str(foldsTotal))
112
+ writeStreamFallback.close()
113
+ print(str(pathFilenamePlanB))
114
+ except Exception:
115
+ print(foldsTotal)
116
+ return None
117
+
118
+ def writeStringToHere(this: str, pathFilename: str | PathLike[Any] | PurePath) -> None:
119
+ """
120
+ Write a string to a file, creating parent directories if needed.
121
+
122
+ Parameters:
123
+ this: The string content to write to the file
124
+ pathFilename: The target file path where the string should be written
125
+ """
126
+ pathFilename = Path(pathFilename)
127
+ pathFilename.parent.mkdir(parents=True, exist_ok=True)
128
+ pathFilename.write_text(str(this))
129
+ return None
@@ -1,3 +1,15 @@
1
+ """
2
+ Interface for retrieving known map folding totals from OEIS (Online Encyclopedia of Integer Sequences).
3
+
4
+ This module provides utilities for accessing pre-computed map folding totals that are known
5
+ from mathematical literature and stored in the OEIS. The functions cache results for
6
+ performance and provide lookups based on map dimensions.
7
+
8
+ The main functions are:
9
+ - makeDictionaryFoldsTotalKnown: Creates a dictionary of known folding totals indexed by map dimensions
10
+ - getFoldsTotalKnown: Retrieves the folding total for a specific map shape, returning -1 if unknown
11
+ """
12
+
1
13
  from functools import cache
2
14
  from mapFolding.oeis import settingsOEIS
3
15
 
@@ -1,4 +1,19 @@
1
- """Everything implementing the The Online Encyclopedia of Integer Sequences (OEIS); _only_ things that implement _only_ the OEIS."""
1
+ """
2
+ Interface to The Online Encyclopedia of Integer Sequences (OEIS) for map folding sequences.
3
+
4
+ This module provides a comprehensive interface for accessing and utilizing integer sequences
5
+ from the OEIS that relate to map folding problems. It implements functionality to:
6
+
7
+ 1. Retrieve sequence data from OEIS with local caching for performance
8
+ 2. Map sequence indices to corresponding map shapes based on sequence definitions
9
+ 3. Provide a command-line interface for sequence lookups
10
+ 4. Execute map folding computations for sequence terms not available in OEIS
11
+
12
+ The module maintains a registry of implemented OEIS sequences (A001415-A001418, A195646)
13
+ with their metadata, known values, and functions to convert between sequence indices and
14
+ map dimensions. This allows the package to validate results against established mathematical
15
+ literature and extend sequences beyond their currently known terms.
16
+ """
2
17
  from collections.abc import Callable
3
18
  from datetime import datetime, timedelta
4
19
  from mapFolding.theSSOT import thePathPackage