piegy 2.1.0__tar.gz → 2.1.9__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 (37) hide show
  1. {piegy-2.1.0/src/piegy.egg-info → piegy-2.1.9}/PKG-INFO +2 -2
  2. {piegy-2.1.0 → piegy-2.1.9}/pyproject.toml +2 -2
  3. piegy-2.1.9/setup.py +85 -0
  4. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/Makefile +17 -20
  5. piegy-2.1.9/src/piegy/C_core/piegyc.so +0 -0
  6. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/__init__.py +1 -0
  7. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/__version__.py +3 -1
  8. piegy-2.1.9/src/piegy/build_info.py +12 -0
  9. piegy-2.1.9/src/piegy/find_C.py +17 -0
  10. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/simulation.py +29 -20
  11. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/simulation_py.py +1 -2
  12. {piegy-2.1.0 → piegy-2.1.9/src/piegy.egg-info}/PKG-INFO +2 -2
  13. {piegy-2.1.0 → piegy-2.1.9}/src/piegy.egg-info/SOURCES.txt +3 -0
  14. piegy-2.1.0/setup.py +0 -35
  15. {piegy-2.1.0 → piegy-2.1.9}/LICENSE.txt +0 -0
  16. {piegy-2.1.0 → piegy-2.1.9}/MANIFEST.in +0 -0
  17. {piegy-2.1.0 → piegy-2.1.9}/README.md +0 -0
  18. {piegy-2.1.0 → piegy-2.1.9}/setup.cfg +0 -0
  19. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/model.c +0 -0
  20. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/model.h +0 -0
  21. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/patch.c +0 -0
  22. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/patch.h +0 -0
  23. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/piegyc.h +0 -0
  24. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/runner.c +0 -0
  25. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/sim_funcs.c +0 -0
  26. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/C_core/sim_funcs.h +0 -0
  27. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/analysis.py +0 -0
  28. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/data_tools.py +0 -0
  29. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/figures.py +0 -0
  30. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/test_var.py +0 -0
  31. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/tools/__init__.py +0 -0
  32. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/tools/figure_tools.py +0 -0
  33. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/tools/file_tools.py +0 -0
  34. {piegy-2.1.0 → piegy-2.1.9}/src/piegy/videos.py +0 -0
  35. {piegy-2.1.0 → piegy-2.1.9}/src/piegy.egg-info/dependency_links.txt +0 -0
  36. {piegy-2.1.0 → piegy-2.1.9}/src/piegy.egg-info/requires.txt +0 -0
  37. {piegy-2.1.0 → piegy-2.1.9}/src/piegy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 2.1.0
3
+ Version: 2.1.9
4
4
  Summary: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory
5
5
  Author-email: Chenning Xu <cxu7@caltech.edu>
6
6
  License: BSD 3-Clause License
@@ -44,7 +44,7 @@ Classifier: Programming Language :: Python :: 3
44
44
  Classifier: Programming Language :: Python :: 3.10
45
45
  Classifier: Programming Language :: Python :: 3.11
46
46
  Classifier: Operating System :: OS Independent
47
- Requires-Python: >=3.8
47
+ Requires-Python: >=3.7
48
48
  Description-Content-Type: text/markdown
49
49
  License-File: LICENSE.txt
50
50
  Requires-Dist: numpy
@@ -4,10 +4,10 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = 'piegy'
7
- version = '2.1.0'
7
+ version = '2.1.9'
8
8
  description = 'Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory'
9
9
  readme = 'README.md'
10
- requires-python = '>=3.8'
10
+ requires-python = '>=3.7'
11
11
  license = {file = "LICENSE.txt"}
12
12
  authors = [
13
13
  {name = 'Chenning Xu', email = 'cxu7@caltech.edu'}
piegy-2.1.9/setup.py ADDED
@@ -0,0 +1,85 @@
1
+ import subprocess
2
+ import sys
3
+ import os
4
+ import re
5
+ from setuptools import setup, Extension
6
+ from setuptools.command.build_ext import build_ext
7
+ from setuptools.command.build_py import build_py
8
+ import platform
9
+ import datetime
10
+ import textwrap
11
+
12
+
13
+ class BuildSharedLib(build_ext):
14
+ def run(self):
15
+ # Build your shared lib first
16
+ subprocess.check_call(['make', '-C', 'src/piegy/C_core', 'clean', 'so'])
17
+ # Then continue with normal build_ext run
18
+ super().run()
19
+
20
+ def build_extension(self, ext):
21
+ if sys.platform == 'win32':
22
+ lib_name = 'piegyc.dll'
23
+ else:
24
+ lib_name = 'piegyc.so'
25
+ so_path = os.path.abspath(f'src/piegy/C_core/{lib_name}')
26
+ target_path = self.get_ext_fullpath(ext.name)
27
+
28
+ os.makedirs(os.path.dirname(target_path), exist_ok=True)
29
+ self.copy_file(so_path, target_path)
30
+
31
+
32
+
33
+ class AddCompileInfo(build_py):
34
+
35
+ def get_version(self):
36
+ version_file = os.path.join('src', 'piegy', '__version__.py')
37
+ with open(version_file, 'r', encoding='utf-8') as f:
38
+ content = f.read()
39
+ # Regex to extract __version__ = '...'
40
+ version_match = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content, re.MULTILINE)
41
+ if version_match:
42
+ return version_match.group(1)
43
+ raise RuntimeError("Unable to find version string.")
44
+
45
+ def generate_build_info(self):
46
+ version = self.get_version()
47
+ build_from = os.environ.get("BUILD_TYPE", "local machine")
48
+ build_info_content = f'''
49
+ """
50
+ Contains build info, whether it's local built, or a pre-compiled wheel.
51
+ Auto-generated at compile time.
52
+ """
53
+
54
+ build_info = {{
55
+ "version": "{version}",
56
+ "built from": "{build_from}",
57
+ "build date": "{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}",
58
+ "python version": "{platform.python_version()}",
59
+ "platform": "{sys.platform}"
60
+ }}
61
+ '''
62
+ return textwrap.dedent(build_info_content[1:])
63
+
64
+
65
+ def run(self):
66
+ # Write build_info.py directly before building python files
67
+ build_info_path = os.path.abspath(os.path.join('src/piegy/build_info.py'))
68
+ with open(build_info_path, 'w') as f:
69
+ f.write(self.generate_build_info())
70
+ super().run()
71
+
72
+
73
+ # Declare the extension module (empty sources)
74
+ ext_modules = [
75
+ Extension('piegy.C_core.piegyc', sources=[])
76
+ ]
77
+
78
+ setup(
79
+ ext_modules=ext_modules,
80
+ cmdclass={'build_ext': BuildSharedLib,
81
+ 'build_py': AddCompileInfo,},
82
+ package_data={"piegy": ["build_info.py"]},
83
+ include_package_data=True,
84
+ )
85
+
@@ -5,40 +5,36 @@ CC = gcc
5
5
 
6
6
  ## Flags for Max Speed ##
7
7
  # standard
8
- CFLAGS_COMMON = -O3 -flto -std=c99 -DNDEBUG -ffp-contract=fast
8
+ CFLAGS_COMMON = -O3 -flto -std=c99 -DNDEBUG -ffp-contract=fast -MMD -MP
9
9
  LDFLAGS_COMMON = -flto
10
10
 
11
11
  ## Flags for Debugging ##
12
12
  # slower, debuggable with lldb, with Address Sanitizer. Don't use in python
13
- #CFLAGS = -g -std=c99 -Wall -Wextra -fsanitize=address,undefined -fno-omit-frame-pointer
13
+ #CFLAGS = -g -std=c99 -Wall -Wextra -MMD -MP -fsanitize=address,undefined -fno-omit-frame-pointer
14
14
  #LDFLAGS = -fsanitize=address,undefined
15
15
  # slower, regular build, allow lldb
16
- #CFLAGS = -g -std=c99 -Wall -Wextra
16
+ #CFLAGS = -g -std=c99 -Wall -Wextra -MMD -MP
17
17
  #LDFLAGS =
18
18
 
19
- # Enable auto header dependency tracking
20
- DEPFLAGS = -MMD -MP
21
- CFLAGS += $(DEPFLAGS)
22
-
23
19
 
24
20
  #### OS specific ####
25
- UNAME_S := $(shell uname -s)
21
+ OS := $(shell uname)
26
22
 
27
- ifeq ($(UNAME_S),Darwin)
28
- # macOS-specific flags
29
- CFLAGS = $(CFLAGS_COMMON) -fPIC -mmacosx-version-min=11.0 -arch arm64 $(DEPFLAGS)
23
+ ifeq ($(OS),Darwin)
24
+ # macOS flags
25
+ CFLAGS = $(CFLAGS_COMMON) -fPIC -mmacosx-version-min=11.0 -arch arm64
30
26
  LDFLAGS = $(LDFLAGS_COMMON)
31
- else ifeq ($(UNAME_S),Linux)
32
- # Linux-specific flags
33
- CFLAGS = $(CFLAGS_COMMON) -fPIC $(DEPFLAGS)
27
+ else ifeq ($(OS),Linux)
28
+ # Linux flags
29
+ CFLAGS = $(CFLAGS_COMMON) -fPIC
34
30
  LDFLAGS = $(LDFLAGS_COMMON)
35
- else ifeq ($(UNAME_S),Windows_NT)
36
- # Windows-specific flags
37
- CFLAGS = $(CFLAGS_COMMON) -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 $(DEPFLAGS)
31
+ else ifeq '$(findstring ;,$(PATH))' ';'
32
+ # windows flags
33
+ CFLAGS = $(CFLAGS_COMMON) -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00
38
34
  LDFLAGS = $(LDFLAGS_COMMON)
39
35
  else
40
36
  # Default fallback
41
- CFLAGS = $(CFLAGS_COMMON) -fPIC $(DEPFLAGS)
37
+ CFLAGS = $(CFLAGS_COMMON) -fPIC
42
38
  LDFLAGS = $(LDFLAGS_COMMON)
43
39
  endif
44
40
 
@@ -56,7 +52,8 @@ DEPS = $(OBJ:.o=.d) $(RUNNER_DEPS)
56
52
 
57
53
  # Executable name
58
54
  TEST = runner
59
- ifeq ($(OS),Windows_NT)
55
+ ifeq '$(findstring ;,$(PATH))' ';'
56
+ # windows
60
57
  SHARED_LIB = piegyc.dll
61
58
  else
62
59
  SHARED_LIB = piegyc.so
@@ -82,7 +79,7 @@ $(SHARED_LIB): $(OBJ)
82
79
 
83
80
  # Compile source files to object files
84
81
  %.o: %.c
85
- $(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@
82
+ $(CC) $(CFLAGS) -c $< -o $@
86
83
 
87
84
  # Clean build files
88
85
  clean:
Binary file
@@ -19,6 +19,7 @@ Last update: May 12, 2025
19
19
  '''
20
20
 
21
21
  from .__version__ import __version__
22
+ from .build_info import build_info
22
23
 
23
24
  from .simulation import model, run, demo_model, UV_expected_val, check_overflow_func
24
25
  from .videos import make_video, SUPPORTED_FIGURES
@@ -1,4 +1,4 @@
1
- __version__ = '2.1.0'
1
+ __version__ = '2.1.9'
2
2
 
3
3
  '''
4
4
  version history:
@@ -28,4 +28,6 @@ version history:
28
28
  2.0.4: minor debuggings.
29
29
  2.0.5: fix error in random number generator.
30
30
  2.1.0: redo random number generator. Update package upload so that more compatible across platforms.
31
+ 2.1.1: fix import bug for the C core.
32
+ 2.1.2 ~ 2.1.9: updating & fixing wheel.
31
33
  '''
@@ -0,0 +1,12 @@
1
+ """
2
+ Contains build info, whether it's local built, or a pre-compiled wheel.
3
+ Auto-generated at compile time.
4
+ """
5
+
6
+ build_info = {
7
+ "version": "2.1.8",
8
+ "built from": "local",
9
+ "build date": "2025-06-28 01:23:08",
10
+ "python version": "3.11.10",
11
+ "platform": "darwin"
12
+ }
@@ -0,0 +1,17 @@
1
+ '''
2
+ This module is used to find the C core
3
+ '''
4
+
5
+ import os
6
+
7
+
8
+ def find_C():
9
+ C_core_path = os.path.join(os.path.dirname(__file__), 'C_core')
10
+ C_list = os.listdir(C_core_path)
11
+ for file in C_list:
12
+ if file[-3:] == '.so':
13
+ return C_core_path + '/' + file
14
+ if file[-4:] == '.pyd':
15
+ return C_core_path + '/' + file
16
+
17
+ raise FileNotFoundError('C computation core not found. You can either compile manully or use the Python core instead. Please see docs.')
@@ -12,6 +12,7 @@ Class & Functions:
12
12
  - check_overflow_func: check whether an overflow might happen in simulation. This is usually done automatically when init-ing a model.
13
13
  '''
14
14
 
15
+ from . import find_C
15
16
 
16
17
  import numpy as np
17
18
  import os
@@ -21,14 +22,15 @@ import numpy as np
21
22
  from numpy.ctypeslib import ndpointer
22
23
 
23
24
 
24
- # path to the C shared libary
25
- C_LIB_PATH = os.path.join(os.path.dirname(__file__), 'C_core', 'piegyc.so')
26
-
27
25
  # check whether overflow / too large values might be encountered
28
26
  # these values are considered as exponents in exp()
29
27
  EXP_OVERFLOW_BOUND = 709 # where exp(x) reaches overflow bound
30
28
  EXP_TOO_LARGE_BOUND = 88 # where exp(x) reaches 1e20
31
29
 
30
+ # read the C core into LIB
31
+ # initialized upon first run
32
+ LIB = None
33
+
32
34
 
33
35
  '''
34
36
  The C core
@@ -69,23 +71,28 @@ class model_c(ctypes.Structure):
69
71
  ptr = getattr(self, name)
70
72
  return np.ctypeslib.as_array(ptr, shape=(self.arr_size,))
71
73
 
72
- lib = ctypes.CDLL(C_LIB_PATH, winmode = 0)
73
- lib.mod_init.argtypes = [
74
- ctypes.POINTER(model_c), c_size_t, c_size_t,
75
- c_double, c_double, c_size_t, c_bool,
76
- ndpointer(dtype=np.uint32, flags="C_CONTIGUOUS"),
77
- ndpointer(dtype=np.float64, flags="C_CONTIGUOUS"),
78
- ndpointer(dtype=np.float64, flags="C_CONTIGUOUS"),
79
- c_int32, c_int32
80
- ]
81
- lib.mod_init.restype = c_bool
82
74
 
83
- lib.mod_free_py.argtypes = [ctypes.POINTER(model_c)]
84
- lib.mod_free_py.restype = None
75
+ def read_lib():
76
+ global LIB
77
+ if LIB != None:
78
+ return
79
+
80
+ LIB = ctypes.CDLL(find_C.find_C(), winmode = 0)
81
+ LIB.mod_init.argtypes = [
82
+ ctypes.POINTER(model_c), c_size_t, c_size_t,
83
+ c_double, c_double, c_size_t, c_bool,
84
+ ndpointer(dtype=np.uint32, flags="C_CONTIGUOUS"),
85
+ ndpointer(dtype=np.float64, flags="C_CONTIGUOUS"),
86
+ ndpointer(dtype=np.float64, flags="C_CONTIGUOUS"),
87
+ c_int32, c_int32
88
+ ]
89
+ LIB.mod_init.restype = c_bool
85
90
 
86
- lib.run.argtypes = [ctypes.POINTER(model_c), ctypes.POINTER(c_char), c_size_t]
87
- lib.run.restype = None
91
+ LIB.mod_free_py.argtypes = [ctypes.POINTER(model_c)]
92
+ LIB.mod_free_py.restype = None
88
93
 
94
+ LIB.run.argtypes = [ctypes.POINTER(model_c), ctypes.POINTER(c_char), c_size_t]
95
+ LIB.run.restype = None
89
96
 
90
97
 
91
98
 
@@ -396,6 +403,8 @@ def run(mod, message = ""):
396
403
  C-cored simulation
397
404
  '''
398
405
 
406
+ read_lib()
407
+
399
408
  if not mod.data_empty:
400
409
  raise ValueError('mod has non-empty data.')
401
410
 
@@ -408,20 +417,20 @@ def run(mod, message = ""):
408
417
  P = np.ascontiguousarray(mod.P.flatten(), dtype = np.float64)
409
418
 
410
419
  mod_c = model_c()
411
- success = lib.mod_init(ctypes.byref(mod_c),
420
+ success = LIB.mod_init(ctypes.byref(mod_c),
412
421
  mod.N, mod.M, mod.maxtime, mod.record_itv, mod.sim_time, mod.boundary,
413
422
  I, X, P, mod.print_pct, mod.seed)
414
423
  if not success:
415
424
  raise RuntimeError('mod_init failed')
416
425
 
417
- lib.run(ctypes.byref(mod_c), msg_buffer, msg_len)
426
+ LIB.run(ctypes.byref(mod_c), msg_buffer, msg_len)
418
427
 
419
428
  mod.set_data(False, mod.max_record, 1, mod_c.get_array('U1d').reshape(mod.N, mod.M, mod.max_record),
420
429
  mod_c.get_array('V1d').reshape(mod.N, mod.M, mod.max_record),
421
430
  mod_c.get_array('Upi_1d').reshape(mod.N, mod.M, mod.max_record),
422
431
  mod_c.get_array('Vpi_1d').reshape(mod.N, mod.M, mod.max_record))
423
432
 
424
- lib.mod_free_py(ctypes.byref(mod_c))
433
+ LIB.mod_free_py(ctypes.byref(mod_c))
425
434
  del mod_c
426
435
 
427
436
 
@@ -5,8 +5,7 @@ But you can still run them by calling:
5
5
  >>> run_py(mod)
6
6
  '''
7
7
 
8
- from . import simulation
9
- model = simulation.model
8
+ from .simulation import model
10
9
 
11
10
  import math
12
11
  import numpy as np
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 2.1.0
3
+ Version: 2.1.9
4
4
  Summary: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory
5
5
  Author-email: Chenning Xu <cxu7@caltech.edu>
6
6
  License: BSD 3-Clause License
@@ -44,7 +44,7 @@ Classifier: Programming Language :: Python :: 3
44
44
  Classifier: Programming Language :: Python :: 3.10
45
45
  Classifier: Programming Language :: Python :: 3.11
46
46
  Classifier: Operating System :: OS Independent
47
- Requires-Python: >=3.8
47
+ Requires-Python: >=3.7
48
48
  Description-Content-Type: text/markdown
49
49
  License-File: LICENSE.txt
50
50
  Requires-Dist: numpy
@@ -6,8 +6,10 @@ setup.py
6
6
  src/piegy/__init__.py
7
7
  src/piegy/__version__.py
8
8
  src/piegy/analysis.py
9
+ src/piegy/build_info.py
9
10
  src/piegy/data_tools.py
10
11
  src/piegy/figures.py
12
+ src/piegy/find_C.py
11
13
  src/piegy/simulation.py
12
14
  src/piegy/simulation_py.py
13
15
  src/piegy/test_var.py
@@ -23,6 +25,7 @@ src/piegy/C_core/model.h
23
25
  src/piegy/C_core/patch.c
24
26
  src/piegy/C_core/patch.h
25
27
  src/piegy/C_core/piegyc.h
28
+ src/piegy/C_core/piegyc.so
26
29
  src/piegy/C_core/runner.c
27
30
  src/piegy/C_core/sim_funcs.c
28
31
  src/piegy/C_core/sim_funcs.h
piegy-2.1.0/setup.py DELETED
@@ -1,35 +0,0 @@
1
- import subprocess
2
- import sys
3
- import os
4
- from setuptools import setup, Extension
5
- from setuptools.command.build_ext import build_ext
6
-
7
- class BuildSharedLib(build_ext):
8
- def run(self):
9
- # Build your shared lib first
10
- subprocess.check_call(['make', '-C', 'src/piegy/C_core', 'clean', 'so'])
11
- # Then continue with normal build_ext run
12
- super().run()
13
-
14
- def build_extension(self, ext):
15
- if sys.platform == 'win32':
16
- lib_name = 'piegyc.dll'
17
- else:
18
- lib_name = 'piegyc.so'
19
- so_path = os.path.abspath(f'src/piegy/C_core/{lib_name}')
20
- target_path = self.get_ext_fullpath(ext.name)
21
-
22
- os.makedirs(os.path.dirname(target_path), exist_ok=True)
23
- self.copy_file(so_path, target_path)
24
-
25
- # Declare the extension module (empty sources)
26
- ext_modules = [
27
- Extension('piegy.C_core.piegyc', sources=[])
28
- ]
29
-
30
- setup(
31
- ext_modules=ext_modules,
32
- cmdclass={'build_ext': BuildSharedLib},
33
- package_data={"piegy": ["C_core/piegyc.so"]},
34
- include_package_data=True,
35
- )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes