mapFolding 0.12.1__py3-none-any.whl → 0.12.3__py3-none-any.whl

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 (37) hide show
  1. mapFolding/__init__.py +46 -20
  2. mapFolding/_theSSOT.py +81 -0
  3. mapFolding/_theTypes.py +148 -0
  4. mapFolding/basecamp.py +62 -47
  5. mapFolding/beDRY.py +100 -73
  6. mapFolding/dataBaskets.py +226 -31
  7. mapFolding/filesystemToolkit.py +161 -107
  8. mapFolding/oeis.py +388 -174
  9. mapFolding/reference/flattened.py +1 -1
  10. mapFolding/someAssemblyRequired/RecipeJob.py +146 -20
  11. mapFolding/someAssemblyRequired/__init__.py +60 -38
  12. mapFolding/someAssemblyRequired/_toolIfThis.py +125 -35
  13. mapFolding/someAssemblyRequired/_toolkitContainers.py +125 -44
  14. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
  15. mapFolding/someAssemblyRequired/infoBooth.py +37 -2
  16. mapFolding/someAssemblyRequired/makeAllModules.py +785 -0
  17. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +161 -74
  18. mapFolding/someAssemblyRequired/toolkitNumba.py +218 -36
  19. mapFolding/someAssemblyRequired/transformationTools.py +125 -58
  20. mapfolding-0.12.3.dist-info/METADATA +163 -0
  21. mapfolding-0.12.3.dist-info/RECORD +53 -0
  22. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/WHEEL +1 -1
  23. tests/__init__.py +28 -44
  24. tests/conftest.py +66 -61
  25. tests/test_computations.py +64 -89
  26. tests/test_filesystem.py +25 -1
  27. tests/test_oeis.py +37 -7
  28. tests/test_other.py +29 -2
  29. tests/test_tasks.py +30 -2
  30. mapFolding/datatypes.py +0 -18
  31. mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +0 -433
  32. mapFolding/theSSOT.py +0 -34
  33. mapfolding-0.12.1.dist-info/METADATA +0 -184
  34. mapfolding-0.12.1.dist-info/RECORD +0 -53
  35. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/entry_points.txt +0 -0
  36. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/licenses/LICENSE +0 -0
  37. {mapfolding-0.12.1.dist-info → mapfolding-0.12.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,785 @@
1
+ """
2
+ Map folding AST transformation system: Comprehensive transformation orchestration and module generation.
3
+
4
+ This module provides the orchestration layer of the map folding AST transformation system,
5
+ implementing comprehensive tools that coordinate all transformation stages to generate optimized
6
+ implementations with diverse computational strategies and performance characteristics. Building
7
+ upon the foundational pattern recognition, structural decomposition, core transformation tools,
8
+ Numba integration, and configuration management established in previous layers, this module
9
+ executes complete transformation processes that convert high-level dataclass-based algorithms
10
+ into specialized variants optimized for specific execution contexts.
11
+
12
+ The transformation orchestration addresses the full spectrum of optimization requirements for
13
+ map folding computational research through systematic application of the complete transformation
14
+ toolkit. The comprehensive approach decomposes dataclass parameters into primitive values for
15
+ Numba compatibility while removing object-oriented overhead and preserving computational logic,
16
+ generates concurrent execution variants using ProcessPoolExecutor with task division and result
17
+ aggregation, creates dedicated modules for counting variable setup with transformed loop conditions,
18
+ and provides theorem-specific transformations with configurable optimization levels including
19
+ trimmed variants and Numba-accelerated implementations.
20
+
21
+ The orchestration process operates through systematic AST manipulation that analyzes source
22
+ algorithms to extract dataclass dependencies, transforms data access patterns, applies performance
23
+ optimizations, and generates specialized modules with consistent naming conventions and filesystem
24
+ organization. The comprehensive transformation process coordinates pattern recognition for structural
25
+ analysis, dataclass decomposition for parameter optimization, function transformation for signature
26
+ adaptation, Numba integration for compilation optimization, and configuration management for
27
+ systematic generation control.
28
+
29
+ Generated modules maintain algorithmic correctness while providing significant performance
30
+ improvements through just-in-time compilation, parallel execution, and optimized data structures
31
+ tailored for specific computational requirements essential to large-scale map folding research.
32
+ """
33
+
34
+ from astToolkit import (
35
+ astModuleToIngredientsFunction, Be, DOT, extractClassDef, extractFunctionDef, Grab, hasDOTbody, identifierDotAttribute,
36
+ IngredientsFunction, IngredientsModule, LedgerOfImports, Make, NodeChanger, NodeTourist, parseLogicalPath2astModule,
37
+ parsePathFilename2astModule, Then)
38
+ from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
39
+ from hunterMakesPy import importLogicalPath2Identifier, raiseIfNone
40
+ from mapFolding import packageSettings
41
+ from mapFolding.someAssemblyRequired import (
42
+ DeReConstructField2ast, IfThis, ShatteredDataclass, sourceCallableDispatcherDEFAULT)
43
+ from mapFolding.someAssemblyRequired.infoBooth import (
44
+ algorithmSourceModuleDEFAULT, dataPackingModuleIdentifierDEFAULT, logicalPathInfixDEFAULT,
45
+ sourceCallableIdentifierDEFAULT, theCountingIdentifierDEFAULT)
46
+ from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
47
+ from mapFolding.someAssemblyRequired.transformationTools import (
48
+ removeDataclassFromFunction, shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
49
+ from os import PathLike
50
+ from pathlib import PurePath
51
+ from typing import Any, cast, TYPE_CHECKING
52
+ import ast
53
+ import dataclasses
54
+
55
+ if TYPE_CHECKING:
56
+ from collections.abc import Sequence
57
+
58
+ def _findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[str, str, str]:
59
+ """Extract dataclass information from a function's AST for transformation operations.
60
+
61
+ (AI generated docstring)
62
+
63
+ Analyzes the first parameter of a function to identify the dataclass type annotation
64
+ and instance identifier, then locates the module where the dataclass is defined by
65
+ examining the function's import statements. This information is essential for
66
+ dataclass decomposition and transformation operations.
67
+
68
+ Parameters
69
+ ----------
70
+ ingredientsFunction : IngredientsFunction
71
+ Function container with AST and import information.
72
+
73
+ Returns
74
+ -------
75
+ dataclassLogicalPathModule : str
76
+ Module logical path where the dataclass is defined.
77
+ dataclassIdentifier : str
78
+ Class name of the dataclass.
79
+ dataclassInstanceIdentifier : str
80
+ Parameter name for the dataclass instance.
81
+
82
+ Raises
83
+ ------
84
+ ValueError
85
+ If dataclass information cannot be extracted from the function.
86
+
87
+ """
88
+ dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
89
+ dataclassIdentifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
90
+ dataclassLogicalPathModule = None
91
+ for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports._dictionaryImportFrom.items(): # noqa: SLF001
92
+ for nameTuple in listNameTuples:
93
+ if nameTuple[0] == dataclassIdentifier:
94
+ dataclassLogicalPathModule = moduleWithLogicalPath
95
+ break
96
+ if dataclassLogicalPathModule:
97
+ break
98
+ dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
99
+ return raiseIfNone(dataclassLogicalPathModule), dataclassIdentifier, dataclassInstanceIdentifier
100
+
101
+ def _getLogicalPath(packageName: str | None = None, logicalPathInfix: str | None = None, moduleIdentifier: str | None = None, *modules: str) -> identifierDotAttribute:
102
+ """Construct logical module path by joining package and module components.
103
+
104
+ (AI generated docstring)
105
+
106
+ Builds a dot-separated logical path string from optional package name, infix path
107
+ components, and module identifiers. This standardizes module path construction
108
+ across the code generation system and ensures consistent naming conventions.
109
+
110
+ Parameters
111
+ ----------
112
+ packageName : str | None = None
113
+ Root package name for the logical path.
114
+ logicalPathInfix : str | None = None
115
+ Middle path component (typically 'syntheticModules').
116
+ moduleIdentifier : str | None = None
117
+ Primary module identifier.
118
+ *modules : str
119
+ Additional module path components to append.
120
+
121
+ Returns
122
+ -------
123
+ logicalPath : identifierDotAttribute
124
+ Dot-separated logical path string suitable for module import operations.
125
+
126
+ """
127
+ listLogicalPathParts: list[str] = []
128
+ if packageName:
129
+ listLogicalPathParts.append(packageName)
130
+ if logicalPathInfix:
131
+ listLogicalPathParts.append(logicalPathInfix)
132
+ if moduleIdentifier:
133
+ listLogicalPathParts.append(moduleIdentifier)
134
+ if modules:
135
+ listLogicalPathParts.extend(modules)
136
+ return '.'.join(listLogicalPathParts)
137
+
138
+ def _getModule(packageName: str | None = packageSettings.identifierPackage, logicalPathInfix: str | None = logicalPathInfixDEFAULT, moduleIdentifier: str | None = algorithmSourceModuleDEFAULT) -> ast.Module:
139
+ """Load source algorithm module as AST for transformation operations.
140
+
141
+ (AI generated docstring)
142
+
143
+ Retrieves the specified module and parses it into an AST representation that can
144
+ be manipulated by the transformation tools. This provides the foundation for all
145
+ code generation operations by making the source algorithms available for analysis
146
+ and modification.
147
+
148
+ Parameters
149
+ ----------
150
+ packageName : str | None = packageSettings.identifierPackage
151
+ Package containing the source module.
152
+ logicalPathInfix : str | None = logicalPathInfixDEFAULT
153
+ Path component within the package structure.
154
+ moduleIdentifier : str | None = algorithmSourceModuleDEFAULT
155
+ Specific module containing the algorithms.
156
+
157
+ Returns
158
+ -------
159
+ astModule : ast.Module
160
+ AST module representation ready for transformation operations.
161
+
162
+ """
163
+ logicalPathSourceModule: identifierDotAttribute = _getLogicalPath(packageName, logicalPathInfix, moduleIdentifier)
164
+ astModule: ast.Module = parseLogicalPath2astModule(logicalPathSourceModule)
165
+ return astModule
166
+
167
+ def _getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix: PathLike[str] | PurePath | str | None = None, moduleIdentifier: str = '', fileExtension: str = packageSettings.fileExtension) -> PurePath:
168
+ """Construct filesystem path for generated module files.
169
+
170
+ (AI generated docstring)
171
+
172
+ Builds the complete filesystem path where generated modules will be written,
173
+ combining root path, optional infix directory, module name, and file extension.
174
+ This ensures consistent file organization across all generated code.
175
+
176
+ Parameters
177
+ ----------
178
+ pathRoot : PathLike[str] | PurePath | None = packageSettings.pathPackage
179
+ Base directory for the package structure.
180
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
181
+ Subdirectory for organizing generated modules.
182
+ moduleIdentifier : str = ''
183
+ Name of the specific module file.
184
+ fileExtension : str = packageSettings.fileExtension
185
+ File extension for Python modules.
186
+
187
+ Returns
188
+ -------
189
+ pathFilename : PurePath
190
+ Complete filesystem path for the generated module file.
191
+
192
+ """
193
+ pathFilename = PurePath(moduleIdentifier + fileExtension)
194
+ if logicalPathInfix:
195
+ pathFilename = PurePath(logicalPathInfix, pathFilename)
196
+ if pathRoot:
197
+ pathFilename = PurePath(pathRoot, pathFilename)
198
+ return pathFilename
199
+
200
+ def makeInitializeGroupsOfFolds(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
201
+ """Generate initialization module for counting variable setup.
202
+
203
+ (AI generated docstring)
204
+
205
+ Creates a specialized module containing initialization logic for the counting variables
206
+ used in map folding computations. The generated function transforms the original
207
+ algorithm's loop conditions to use equality comparisons instead of greater-than
208
+ comparisons, optimizing the initialization phase.
209
+
210
+ This transformation is particularly important for ensuring that counting variables
211
+ are properly initialized before the main computational loops begin executing.
212
+
213
+ Parameters
214
+ ----------
215
+ astModule : ast.Module
216
+ Source module containing the base algorithm.
217
+ moduleIdentifier : str
218
+ Name for the generated initialization module.
219
+ callableIdentifier : str | None = None
220
+ Name for the initialization function.
221
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
222
+ Directory path for organizing the generated module.
223
+ sourceCallableDispatcher : str | None = None
224
+ Optional dispatcher function identifier.
225
+
226
+ Returns
227
+ -------
228
+ pathFilename : PurePath
229
+ Filesystem path where the initialization module was written.
230
+
231
+ """
232
+ sourceCallableIdentifier: identifierDotAttribute = sourceCallableIdentifierDEFAULT
233
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
234
+ ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
235
+
236
+ dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
237
+ theCountingIdentifier: identifierDotAttribute = theCountingIdentifierDEFAULT
238
+
239
+ findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
240
+ doThat = Grab.testAttribute(Grab.andDoAllOf([Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier)))]))
241
+ NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef.body[0])
242
+
243
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
244
+ write_astModule(IngredientsModule(ingredientsFunction), pathFilename, packageSettings.identifierPackage)
245
+
246
+ return pathFilename
247
+
248
+ def makeDaoOfMapFolding(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
249
+ """Generate Numba-optimized sequential implementation of map folding algorithm.
250
+
251
+ (AI generated docstring)
252
+
253
+ Creates a high-performance sequential version of the map folding algorithm by
254
+ decomposing dataclass parameters into individual primitive values, removing
255
+ dataclass dependencies that are incompatible with Numba, applying Numba
256
+ decorators for just-in-time compilation, and optionally including a dispatcher
257
+ function for dataclass integration.
258
+
259
+ The generated module provides significant performance improvements over the
260
+ original dataclass-based implementation while maintaining algorithmic correctness.
261
+ The transformation preserves all computational logic while restructuring data
262
+ access patterns for optimal Numba compilation.
263
+
264
+ Parameters
265
+ ----------
266
+ astModule : ast.Module
267
+ Source module containing the base algorithm.
268
+ moduleIdentifier : str
269
+ Name for the generated optimized module.
270
+ callableIdentifier : str | None = None
271
+ Name for the main computational function.
272
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
273
+ Directory path for organizing the generated module.
274
+ sourceCallableDispatcher : str | None = None
275
+ Optional dispatcher function for dataclass integration.
276
+
277
+ Returns
278
+ -------
279
+ pathFilename : PurePath
280
+ Filesystem path where the optimized module was written.
281
+
282
+ """
283
+ sourceCallableIdentifier: identifierDotAttribute = sourceCallableIdentifierDEFAULT
284
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
285
+ ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
286
+
287
+ shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*_findDataclass(ingredientsFunction))
288
+
289
+ ingredientsFunction.imports.update(shatteredDataclass.imports)
290
+ ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
291
+ ingredientsFunction = removeUnusedParameters(ingredientsFunction)
292
+ ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
293
+
294
+ ingredientsModule = IngredientsModule(ingredientsFunction)
295
+
296
+ if sourceCallableDispatcher is not None:
297
+
298
+ ingredientsFunctionDispatcher: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableDispatcher)
299
+ ingredientsFunctionDispatcher.imports.update(shatteredDataclass.imports)
300
+ targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
301
+ ingredientsFunctionDispatcher = unpackDataclassCallFunctionRepackDataclass(ingredientsFunctionDispatcher, targetCallableIdentifier, shatteredDataclass)
302
+ astTuple: ast.Tuple = cast('ast.Tuple', raiseIfNone(NodeTourist[ast.Return, ast.expr | None](Be.Return.valueIs(Be.Tuple)
303
+ , doThat=Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef)))
304
+ astTuple.ctx = ast.Store()
305
+
306
+ changeAssignCallToTarget = NodeChanger(
307
+ findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
308
+ , doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts))))
309
+ changeAssignCallToTarget.visit(ingredientsFunctionDispatcher.astFunctionDef)
310
+
311
+ ingredientsModule.appendIngredientsFunction(ingredientsFunctionDispatcher)
312
+
313
+ ingredientsModule.removeImportFromModule('numpy')
314
+
315
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
316
+
317
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
318
+
319
+ return pathFilename
320
+
321
+ def makeDaoOfMapFoldingParallel(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001, PLR0915
322
+ """Generate parallel implementation with concurrent execution and task division.
323
+
324
+ This version of the algorithm: Creates a parallel processing version of the map folding algorithm that distributes
325
+ computational work across multiple processes using `ProcessPoolExecutor`. The implementation includes dataclass decomposition
326
+ for both base and parallel state fields, task division logic that partitions work based on leaf indices, concurrent execution
327
+ management with future objects, result aggregation from multiple parallel computations, and Numba optimization for the core
328
+ computational kernels.
329
+
330
+ The generated module contains multiple functions including core counting function with parallel-aware task filtering,
331
+ dataclass unpacking/repacking function for process communication, and main dispatcher function that manages the parallel
332
+ execution pipeline.
333
+
334
+ Parameters
335
+ ----------
336
+ astModule : ast.Module
337
+ Source module containing the base algorithm.
338
+ moduleIdentifier : str
339
+ Name for the generated parallel module.
340
+ callableIdentifier : str | None = None
341
+ Name for the core parallel counting function.
342
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
343
+ Directory path for organizing the generated module.
344
+ sourceCallableDispatcher : str | None = None
345
+ Optional dispatcher function identifier.
346
+
347
+ Returns
348
+ -------
349
+ pathFilename : PurePath
350
+ Filesystem path where the parallel module was written.
351
+
352
+ """
353
+ sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
354
+ if callableIdentifier is None:
355
+ callableIdentifier = sourceCallableIdentifier
356
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
357
+ ingredientsFunction.astFunctionDef.name = callableIdentifier
358
+
359
+ dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
360
+ dataclassIdentifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
361
+
362
+ dataclassLogicalPathModule = None
363
+ for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports._dictionaryImportFrom.items(): # noqa: SLF001
364
+ for nameTuple in listNameTuples:
365
+ if nameTuple[0] == dataclassIdentifier:
366
+ dataclassLogicalPathModule = moduleWithLogicalPath
367
+ break
368
+ if dataclassLogicalPathModule:
369
+ break
370
+ if dataclassLogicalPathModule is None:
371
+ raise Exception # noqa: TRY002
372
+ dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
373
+ shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclassIdentifier, dataclassInstanceIdentifier)
374
+
375
+ # START add the parallel state fields to the count function ------------------------------------------------
376
+ dataclassBaseFields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifier)) # pyright: ignore [reportArgumentType]
377
+ dataclassIdentifierParallel: identifierDotAttribute = 'Parallel' + dataclassIdentifier
378
+ dataclassFieldsParallel: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifierParallel)) # pyright: ignore [reportArgumentType]
379
+ onlyParallelFields: list[dataclasses.Field[Any]] = [field for field in dataclassFieldsParallel if field.name not in [fieldBase.name for fieldBase in dataclassBaseFields]]
380
+
381
+ Official_fieldOrder: list[str] = []
382
+ dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
383
+
384
+ dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(dataclassLogicalPathModule), dataclassIdentifierParallel)
385
+ if not dataclassClassDef:
386
+ message = f"I could not find `{dataclassIdentifierParallel = }` in `{dataclassLogicalPathModule = }`."
387
+ raise ValueError(message)
388
+
389
+ for aField in onlyParallelFields:
390
+ Official_fieldOrder.append(aField.name)
391
+ dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(dataclassLogicalPathModule, dataclassClassDef, dataclassInstanceIdentifier, aField)
392
+
393
+ shatteredDataclassParallel = ShatteredDataclass(
394
+ countingVariableAnnotation=shatteredDataclass.countingVariableAnnotation,
395
+ countingVariableName=shatteredDataclass.countingVariableName,
396
+ field2AnnAssign={**shatteredDataclass.field2AnnAssign, **{dictionaryDeReConstruction[field].name: dictionaryDeReConstruction[field].astAnnAssignConstructor for field in Official_fieldOrder}},
397
+ Z0Z_field2AnnAssign={**shatteredDataclass.Z0Z_field2AnnAssign, **{dictionaryDeReConstruction[field].name: dictionaryDeReConstruction[field].Z0Z_hack for field in Official_fieldOrder}},
398
+ list_argAnnotated4ArgumentsSpecification=shatteredDataclass.list_argAnnotated4ArgumentsSpecification + [dictionaryDeReConstruction[field].ast_argAnnotated for field in Official_fieldOrder],
399
+ list_keyword_field__field4init=shatteredDataclass.list_keyword_field__field4init + [dictionaryDeReConstruction[field].ast_keyword_field__field for field in Official_fieldOrder if dictionaryDeReConstruction[field].init],
400
+ listAnnotations=shatteredDataclass.listAnnotations + [dictionaryDeReConstruction[field].astAnnotation for field in Official_fieldOrder],
401
+ listName4Parameters=shatteredDataclass.listName4Parameters + [dictionaryDeReConstruction[field].astName for field in Official_fieldOrder],
402
+ listUnpack=shatteredDataclass.listUnpack + [Make.AnnAssign(dictionaryDeReConstruction[field].astName, dictionaryDeReConstruction[field].astAnnotation, dictionaryDeReConstruction[field].ast_nameDOTname) for field in Official_fieldOrder],
403
+ map_stateDOTfield2Name={**shatteredDataclass.map_stateDOTfield2Name, **{dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder}},
404
+ )
405
+ shatteredDataclassParallel.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclassParallel.listName4Parameters, ast.Store())
406
+ shatteredDataclassParallel.repack = Make.Assign([Make.Name(dataclassInstanceIdentifier)], value=Make.Call(Make.Name(dataclassIdentifierParallel), list_keyword=shatteredDataclassParallel.list_keyword_field__field4init))
407
+ shatteredDataclassParallel.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclassParallel.listAnnotations))
408
+
409
+ shatteredDataclassParallel.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
410
+ shatteredDataclassParallel.imports.addImportFrom_asStr(dataclassLogicalPathModule, dataclassIdentifierParallel)
411
+ shatteredDataclassParallel.imports.update(shatteredDataclass.imports)
412
+ shatteredDataclassParallel.imports.removeImportFrom(dataclassLogicalPathModule, dataclassIdentifier)
413
+
414
+ # END add the parallel state fields to the count function ------------------------------------------------
415
+
416
+ ingredientsFunction.imports.update(shatteredDataclassParallel.imports)
417
+ ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclassParallel)
418
+
419
+ # START add the parallel logic to the count function ------------------------------------------------
420
+
421
+ findThis = Be.While.testIs(Be.Compare.leftIs(IfThis.isNameIdentifier('leafConnectee')))
422
+ captureCountGapsCodeBlock: NodeTourist[ast.While, Sequence[ast.stmt]] = NodeTourist(findThis, doThat = Then.extractIt(DOT.body))
423
+ countGapsCodeBlock: Sequence[ast.stmt] = raiseIfNone(captureCountGapsCodeBlock.captureLastMatch(ingredientsFunction.astFunctionDef))
424
+
425
+ thisIsMyTaskIndexCodeBlock = ast.If(ast.BoolOp(ast.Or()
426
+ , values=[ast.Compare(ast.Name('leaf1ndex'), ops=[ast.NotEq()], comparators=[ast.Name('taskDivisions')])
427
+ , ast.Compare(Make.Mod.join([ast.Name('leafConnectee'), ast.Name('taskDivisions')]), ops=[ast.Eq()], comparators=[ast.Name('taskIndex')])])
428
+ , body=list(countGapsCodeBlock[0:-1]))
429
+
430
+ countGapsCodeBlockNew: list[ast.stmt] = [thisIsMyTaskIndexCodeBlock, countGapsCodeBlock[-1]]
431
+ NodeChanger[ast.While, hasDOTbody](findThis, doThat = Grab.bodyAttribute(Then.replaceWith(countGapsCodeBlockNew))).visit(ingredientsFunction.astFunctionDef)
432
+
433
+ # END add the parallel logic to the count function ------------------------------------------------
434
+
435
+ ingredientsFunction = removeUnusedParameters(ingredientsFunction)
436
+
437
+ ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
438
+
439
+ # START unpack/repack the dataclass function ------------------------------------------------
440
+ sourceCallableIdentifier = sourceCallableDispatcherDEFAULT
441
+
442
+ unRepackDataclass: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableIdentifier)
443
+ unRepackDataclass.astFunctionDef.name = 'unRepack' + dataclassIdentifierParallel
444
+ unRepackDataclass.imports.update(shatteredDataclassParallel.imports)
445
+ NodeChanger(
446
+ findThis = Be.arg.annotationIs(Be.Name.idIs(lambda thisAttribute: thisAttribute == dataclassIdentifier)) # pyright: ignore[reportArgumentType]
447
+ , doThat = Grab.annotationAttribute(Grab.idAttribute(Then.replaceWith(dataclassIdentifierParallel)))
448
+ ).visit(unRepackDataclass.astFunctionDef)
449
+ unRepackDataclass.astFunctionDef.returns = Make.Name(dataclassIdentifierParallel)
450
+ targetCallableIdentifier: identifierDotAttribute = ingredientsFunction.astFunctionDef.name
451
+ unRepackDataclass = unpackDataclassCallFunctionRepackDataclass(unRepackDataclass, targetCallableIdentifier, shatteredDataclassParallel)
452
+
453
+ astTuple: ast.Tuple = raiseIfNone(NodeTourist[ast.Return, ast.Tuple](Be.Return, Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef)) # pyright: ignore[reportArgumentType]
454
+ astTuple.ctx = ast.Store()
455
+ changeAssignCallToTarget: NodeChanger[ast.Assign, ast.Assign] = NodeChanger(
456
+ findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
457
+ , doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
458
+ )
459
+ changeAssignCallToTarget.visit(unRepackDataclass.astFunctionDef)
460
+
461
+ ingredientsDoTheNeedful: IngredientsFunction = IngredientsFunction(
462
+ astFunctionDef = Make.FunctionDef('doTheNeedful'
463
+ , argumentSpecification=Make.arguments(list_arg=[Make.arg('state', annotation=Make.Name(dataclassIdentifierParallel)), Make.arg('concurrencyLimit', annotation=Make.Name('int'))])
464
+ , body=[Make.Assign([Make.Name('stateParallel', ast.Store())], value=Make.Call(Make.Name('deepcopy'), listParameters=[Make.Name('state')]))
465
+ , Make.AnnAssign(Make.Name('listStatesParallel', ast.Store()), annotation=Make.Subscript(value=Make.Name('list'), slice=Make.Name(dataclassIdentifierParallel))
466
+ , value=Make.Mult.join([Make.List([Make.Name('stateParallel')]), Make.Attribute(Make.Name('stateParallel'), 'taskDivisions')]))
467
+ , Make.AnnAssign(Make.Name('groupsOfFoldsTotal', ast.Store()), annotation=Make.Name('int'), value=Make.Constant(value=0))
468
+
469
+ , Make.AnnAssign(Make.Name('dictionaryConcurrency', ast.Store()), annotation=Make.Subscript(value=Make.Name('dict'), slice=Make.Tuple([Make.Name('int'), Make.Subscript(value=Make.Name('ConcurrentFuture'), slice=Make.Name(dataclassIdentifierParallel))])), value=Make.Dict())
470
+ , Make.With(items=[Make.withitem(context_expr=Make.Call(Make.Name('ProcessPoolExecutor'), listParameters=[Make.Name('concurrencyLimit')]), optional_vars=Make.Name('concurrencyManager', ast.Store()))]
471
+ , body=[Make.For(Make.Name('indexSherpa', ast.Store()), iter=Make.Call(Make.Name('range'), listParameters=[Make.Attribute(Make.Name('stateParallel'), 'taskDivisions')])
472
+ , body=[Make.Assign([Make.Name('state', ast.Store())], value=Make.Call(Make.Name('deepcopy'), listParameters=[Make.Name('stateParallel')]))
473
+ , Make.Assign([Make.Attribute(Make.Name('state'), 'taskIndex', context=ast.Store())], value=Make.Name('indexSherpa'))
474
+ , Make.Assign([Make.Subscript(Make.Name('dictionaryConcurrency'), slice=Make.Name('indexSherpa'), context=ast.Store())], value=Make.Call(Make.Attribute(Make.Name('concurrencyManager'), 'submit'), listParameters=[Make.Name(unRepackDataclass.astFunctionDef.name), Make.Name('state')]))])
475
+ , Make.For(Make.Name('indexSherpa', ast.Store()), iter=Make.Call(Make.Name('range'), listParameters=[Make.Attribute(Make.Name('stateParallel'), 'taskDivisions')])
476
+ , body=[Make.Assign([Make.Subscript(Make.Name('listStatesParallel'), slice=Make.Name('indexSherpa'), context=ast.Store())], value=Make.Call(Make.Attribute(Make.Subscript(Make.Name('dictionaryConcurrency'), slice=Make.Name('indexSherpa')), 'result')))
477
+ , Make.AugAssign(Make.Name('groupsOfFoldsTotal', ast.Store()), op=ast.Add(), value=Make.Attribute(Make.Subscript(Make.Name('listStatesParallel'), slice=Make.Name('indexSherpa')), 'groupsOfFolds'))])])
478
+
479
+ , Make.AnnAssign(Make.Name('foldsTotal', ast.Store()), annotation=Make.Name('int'), value=Make.Mult.join([Make.Name('groupsOfFoldsTotal'), Make.Attribute(Make.Name('stateParallel'), 'leavesTotal')]))
480
+ , Make.Return(Make.Tuple([Make.Name('foldsTotal'), Make.Name('listStatesParallel')]))]
481
+ , returns=Make.Subscript(Make.Name('tuple'), slice=Make.Tuple([Make.Name('int'), Make.Subscript(Make.Name('list'), slice=Make.Name(dataclassIdentifierParallel))])))
482
+ , imports = LedgerOfImports(Make.Module([Make.ImportFrom('concurrent.futures', list_alias=[Make.alias('Future', asName='ConcurrentFuture'), Make.alias('ProcessPoolExecutor')]),
483
+ Make.ImportFrom('copy', list_alias=[Make.alias('deepcopy')]),
484
+ Make.ImportFrom('multiprocessing', list_alias=[Make.alias('set_start_method', asName='multiprocessing_set_start_method')])])
485
+ )
486
+ )
487
+
488
+ ingredientsModule = IngredientsModule([ingredientsFunction, unRepackDataclass, ingredientsDoTheNeedful]
489
+ , prologue = Make.Module([Make.If(test=Make.Compare(left=Make.Name('__name__'), ops=[Make.Eq()], comparators=[Make.Constant('__main__')]), body=[Make.Expr(Make.Call(Make.Name('multiprocessing_set_start_method'), listParameters=[Make.Constant('spawn')]))])])
490
+ )
491
+ ingredientsModule.removeImportFromModule('numpy')
492
+
493
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
494
+
495
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
496
+
497
+ return pathFilename
498
+
499
+ def makeTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
500
+ """Generate optimized implementation applying Theorem 2 mathematical optimizations.
501
+
502
+ (AI generated docstring)
503
+
504
+ Creates a specialized version of the map folding algorithm that applies Theorem 2
505
+ optimizations for improved computational efficiency. The transformation includes
506
+ modifying loop termination conditions from general cases to Theorem 2 specifics,
507
+ restructuring conditional logic to eliminate unnecessary branch evaluations,
508
+ adding count doubling operations to leverage mathematical properties, and
509
+ removing redundant computations that are not needed under Theorem 2 constraints.
510
+
511
+ Theorem 2 provides mathematical guarantees that allow certain computational
512
+ shortcuts and optimizations that would not be valid in the general case. This
513
+ implementation capitalizes on those properties to achieve significant performance
514
+ improvements for maps that satisfy Theorem 2 conditions.
515
+
516
+ Parameters
517
+ ----------
518
+ astModule : ast.Module
519
+ Source module containing the base algorithm.
520
+ moduleIdentifier : str
521
+ Name for the generated theorem-optimized module.
522
+ callableIdentifier : str | None = None
523
+ Name for the optimized computational function.
524
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
525
+ Directory path for organizing the generated module.
526
+ sourceCallableDispatcher : str | None = None
527
+ Currently not implemented for this transformation.
528
+
529
+ Returns
530
+ -------
531
+ pathFilename : PurePath
532
+ Filesystem path where the theorem-optimized module was written.
533
+
534
+ Raises
535
+ ------
536
+ NotImplementedError
537
+ If `sourceCallableDispatcher` is provided.
538
+
539
+ """
540
+ sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
541
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
542
+ ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
543
+
544
+ dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
545
+
546
+ NodeChanger(
547
+ findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
548
+ , doThat = Grab.testAttribute(Grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)])))
549
+ ).visit(ingredientsFunction.astFunctionDef)
550
+
551
+ insertLeaf = NodeTourist(
552
+ findThis = IfThis.isIfAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
553
+ , doThat = Then.extractIt(DOT.body)
554
+ ).captureLastMatch(ingredientsFunction.astFunctionDef)
555
+ NodeChanger(
556
+ findThis = IfThis.isIfAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
557
+ , doThat = Then.replaceWith(insertLeaf)
558
+ ).visit(ingredientsFunction.astFunctionDef)
559
+
560
+ NodeChanger(
561
+ findThis = IfThis.isAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
562
+ , doThat = Then.removeIt
563
+ ).visit(ingredientsFunction.astFunctionDef)
564
+
565
+ NodeChanger(
566
+ findThis = IfThis.isAttributeNamespaceIdentifierLessThanOrEqual0(dataclassInstanceIdentifier, 'leaf1ndex')
567
+ , doThat = Then.removeIt
568
+ ).visit(ingredientsFunction.astFunctionDef)
569
+
570
+ theCountingIdentifier: identifierDotAttribute = theCountingIdentifierDEFAULT
571
+ doubleTheCount: ast.AugAssign = Make.AugAssign(Make.Attribute(ast.Name(dataclassInstanceIdentifier), theCountingIdentifier), ast.Mult(), Make.Constant(2))
572
+ NodeChanger(
573
+ findThis = Be.Return
574
+ , doThat = Then.insertThisAbove([doubleTheCount])
575
+ ).visit(ingredientsFunction.astFunctionDef)
576
+
577
+ ingredientsModule = IngredientsModule(ingredientsFunction)
578
+
579
+ if sourceCallableDispatcher is not None:
580
+ message = 'sourceCallableDispatcher is not implemented yet'
581
+ raise NotImplementedError(message)
582
+
583
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
584
+
585
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
586
+
587
+ return pathFilename
588
+
589
+ def trimTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
590
+ """Generate constrained Theorem 2 implementation by removing unnecessary logic.
591
+
592
+ (AI generated docstring)
593
+
594
+ Creates a trimmed version of the Theorem 2 implementation by eliminating
595
+ conditional logic that is not needed under specific constraint assumptions.
596
+ This transformation removes checks for unconstrained dimensions, simplifying
597
+ the algorithm for cases where dimensional constraints are guaranteed to be
598
+ satisfied by external conditions.
599
+
600
+ The trimming operation is particularly valuable for generating lean implementations
601
+ where the calling context ensures that certain conditions will always be met,
602
+ allowing the removal of defensive programming constructs that add computational
603
+ overhead without providing benefits in the constrained environment.
604
+
605
+ Parameters
606
+ ----------
607
+ astModule : ast.Module
608
+ Source module containing the Theorem 2 implementation.
609
+ moduleIdentifier : str
610
+ Name for the generated trimmed module.
611
+ callableIdentifier : str | None = None
612
+ Name for the trimmed computational function.
613
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
614
+ Directory path for organizing the generated module.
615
+ sourceCallableDispatcher : str | None = None
616
+ Optional dispatcher function identifier (unused).
617
+
618
+ Returns
619
+ -------
620
+ pathFilename : PurePath
621
+ Filesystem path where the trimmed module was written.
622
+
623
+ """
624
+ sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
625
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
626
+ ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
627
+
628
+ dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
629
+
630
+ findThis = IfThis.isIfUnaryNotAttributeNamespaceIdentifier(dataclassInstanceIdentifier, 'dimensionsUnconstrained')
631
+ doThat = Then.removeIt
632
+ NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
633
+
634
+ ingredientsModule = IngredientsModule(ingredientsFunction)
635
+ ingredientsModule.removeImportFromModule('numpy')
636
+
637
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
638
+
639
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
640
+
641
+ return pathFilename
642
+
643
+ def numbaOnTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
644
+ """Generate Numba-accelerated Theorem 2 implementation with dataclass decomposition.
645
+
646
+ (AI generated docstring)
647
+
648
+ Creates a highly optimized version of the Theorem 2 algorithm by combining the
649
+ mathematical optimizations of Theorem 2 with Numba just-in-time compilation.
650
+ The transformation includes dataclass decomposition to convert structured
651
+ parameters into primitives, removal of Python object dependencies incompatible
652
+ with Numba, application of Numba decorators for maximum performance, and type
653
+ annotation optimization for efficient compilation.
654
+
655
+ This represents the highest level of optimization available for Theorem 2
656
+ implementations, providing both mathematical efficiency through theorem
657
+ application and computational efficiency through Numba acceleration.
658
+ The result is suitable for production use in high-performance computing
659
+ environments where maximum speed is required.
660
+
661
+ Parameters
662
+ ----------
663
+ astModule : ast.Module
664
+ Source module containing the Theorem 2 implementation.
665
+ moduleIdentifier : str
666
+ Name for the generated Numba-accelerated module.
667
+ callableIdentifier : str | None = None
668
+ Name for the accelerated computational function.
669
+ logicalPathInfix : PathLike[str] | PurePath | str | None = None
670
+ Directory path for organizing the generated module.
671
+ sourceCallableDispatcher : str | None = None
672
+ Optional dispatcher function identifier (unused).
673
+
674
+ Returns
675
+ -------
676
+ pathFilename : PurePath
677
+ Filesystem path where the accelerated module was written.
678
+
679
+ """
680
+ sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
681
+ if callableIdentifier is None:
682
+ callableIdentifier = sourceCallableIdentifier
683
+ ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
684
+ ingredientsFunction.astFunctionDef.name = callableIdentifier
685
+
686
+ shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*_findDataclass(ingredientsFunction))
687
+
688
+ ingredientsFunction.imports.update(shatteredDataclass.imports)
689
+ ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
690
+ ingredientsFunction = removeUnusedParameters(ingredientsFunction)
691
+ ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
692
+
693
+ ingredientsModule = IngredientsModule(ingredientsFunction)
694
+ ingredientsModule.removeImportFromModule('numpy')
695
+
696
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
697
+
698
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
699
+
700
+ return pathFilename
701
+
702
+ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom) -> None:
703
+ """Generate interface module for dataclass unpacking and repacking operations.
704
+
705
+ (AI generated docstring)
706
+
707
+ Creates a specialized module that serves as an interface between dataclass-based
708
+ calling code and optimized implementations that operate on decomposed primitive
709
+ values. The generated module includes a function that unpacks dataclass instances
710
+ into individual primitive values, calls to the specified optimized target function
711
+ with decomposed parameters, repacking of results back into appropriate dataclass
712
+ instances, and import management for all required dependencies.
713
+
714
+ This bridge module enables seamless integration between high-level dataclass-based
715
+ APIs and low-level optimized implementations, maintaining type safety and usability
716
+ while leveraging performance optimizations that require primitive value operations.
717
+
718
+ Parameters
719
+ ----------
720
+ astImportFrom : ast.ImportFrom
721
+ Import statement specifying the target optimized function to call.
722
+
723
+ Returns
724
+ -------
725
+ None
726
+ The generated module is written directly to the filesystem.
727
+
728
+ """
729
+ callableIdentifierHARDCODED: str = 'sequential'
730
+
731
+ algorithmSourceModule: identifierDotAttribute = algorithmSourceModuleDEFAULT
732
+ sourceCallableIdentifier: identifierDotAttribute = sourceCallableDispatcherDEFAULT
733
+ logicalPathSourceModule: identifierDotAttribute = '.'.join([packageSettings.identifierPackage, algorithmSourceModule]) # noqa: FLY002
734
+
735
+ logicalPathInfix: identifierDotAttribute = logicalPathInfixDEFAULT
736
+ moduleIdentifier: identifierDotAttribute = dataPackingModuleIdentifierDEFAULT
737
+ callableIdentifier: identifierDotAttribute = callableIdentifierHARDCODED
738
+
739
+ ingredientsFunction: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
740
+ ingredientsFunction.astFunctionDef.name = callableIdentifier
741
+
742
+ shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*_findDataclass(ingredientsFunction))
743
+
744
+ ingredientsFunction.imports.update(shatteredDataclass.imports)
745
+ ingredientsFunction.imports.addAst(astImportFrom)
746
+ targetCallableIdentifier = astImportFrom.names[0].name
747
+ ingredientsFunction = raiseIfNone(unpackDataclassCallFunctionRepackDataclass(ingredientsFunction, targetCallableIdentifier, shatteredDataclass))
748
+ targetFunctionDef: ast.FunctionDef = raiseIfNone(extractFunctionDef(parseLogicalPath2astModule(raiseIfNone(astImportFrom.module)), targetCallableIdentifier))
749
+ astTuple: ast.Tuple = cast('ast.Tuple', raiseIfNone(NodeTourist[ast.Return, ast.expr | None](Be.Return.valueIs(Be.Tuple)
750
+ , doThat=Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)))
751
+ astTuple.ctx = ast.Store()
752
+
753
+ changeAssignCallToTarget = NodeChanger(
754
+ findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
755
+ , doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts))))
756
+ changeAssignCallToTarget.visit(ingredientsFunction.astFunctionDef)
757
+
758
+ ingredientsModule = IngredientsModule(ingredientsFunction)
759
+ ingredientsModule.removeImportFromModule('numpy')
760
+
761
+ pathFilename: PurePath = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
762
+
763
+ write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
764
+
765
+ if __name__ == '__main__':
766
+ astModule: ast.Module = _getModule(logicalPathInfix=None)
767
+ makeInitializeGroupsOfFolds(astModule, 'initializeCount', 'initializeGroupsOfFolds', logicalPathInfixDEFAULT)
768
+
769
+ astModule = _getModule(logicalPathInfix=None)
770
+ pathFilename: PurePath = makeDaoOfMapFolding(astModule, 'daoOfMapFolding', None, logicalPathInfixDEFAULT, sourceCallableDispatcherDEFAULT)
771
+
772
+ astModule = _getModule(logicalPathInfix=None)
773
+ pathFilename = makeDaoOfMapFoldingParallel(astModule, 'countParallel', None, logicalPathInfixDEFAULT, sourceCallableDispatcherDEFAULT)
774
+
775
+ astModule = _getModule(logicalPathInfix=None)
776
+ pathFilename = makeTheorem2(astModule, 'theorem2', None, logicalPathInfixDEFAULT, None)
777
+
778
+ astModule = parsePathFilename2astModule(pathFilename)
779
+ pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None, logicalPathInfixDEFAULT, None)
780
+
781
+ astModule = parsePathFilename2astModule(pathFilename)
782
+ pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None, logicalPathInfixDEFAULT, None)
783
+
784
+ astImportFrom: ast.ImportFrom = Make.ImportFrom(_getLogicalPath(packageSettings.identifierPackage, logicalPathInfixDEFAULT, 'theorem2Numba'), list_alias=[Make.alias(sourceCallableIdentifierDEFAULT)])
785
+ makeUnRePackDataclass(astImportFrom)