piegy 2.1.8__pp37-pypy37_pp73-win_amd64.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.
- piegy/C_core/Makefile +97 -0
- piegy/C_core/model.c +108 -0
- piegy/C_core/model.h +54 -0
- piegy/C_core/patch.c +43 -0
- piegy/C_core/patch.h +43 -0
- piegy/C_core/piegyc.h +49 -0
- piegy/C_core/piegyc.pypy37-pp73-win_amd64.pyd +0 -0
- piegy/C_core/runner.c +61 -0
- piegy/C_core/sim_funcs.c +561 -0
- piegy/C_core/sim_funcs.h +547 -0
- piegy/__init__.py +57 -0
- piegy/__version__.py +33 -0
- piegy/analysis.py +222 -0
- piegy/build_info.py +12 -0
- piegy/data_tools.py +127 -0
- piegy/figures.py +491 -0
- piegy/find_C.py +17 -0
- piegy/simulation.py +509 -0
- piegy/simulation_py.py +816 -0
- piegy/test_var.py +583 -0
- piegy/tools/__init__.py +15 -0
- piegy/tools/figure_tools.py +238 -0
- piegy/tools/file_tools.py +29 -0
- piegy/videos.py +303 -0
- piegy-2.1.8.dist-info/LICENSE.txt +28 -0
- piegy-2.1.8.dist-info/METADATA +112 -0
- piegy-2.1.8.dist-info/RECORD +29 -0
- piegy-2.1.8.dist-info/WHEEL +5 -0
- piegy-2.1.8.dist-info/top_level.txt +1 -0
piegy/C_core/Makefile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Compiler and flags
|
2
|
+
CC = gcc
|
3
|
+
|
4
|
+
#### Common Flags ####
|
5
|
+
|
6
|
+
## Flags for Max Speed ##
|
7
|
+
# standard
|
8
|
+
CFLAGS_COMMON = -O3 -flto -std=c99 -DNDEBUG -ffp-contract=fast -MMD -MP
|
9
|
+
LDFLAGS_COMMON = -flto
|
10
|
+
|
11
|
+
## Flags for Debugging ##
|
12
|
+
# slower, debuggable with lldb, with Address Sanitizer. Don't use in python
|
13
|
+
#CFLAGS = -g -std=c99 -Wall -Wextra -MMD -MP -fsanitize=address,undefined -fno-omit-frame-pointer
|
14
|
+
#LDFLAGS = -fsanitize=address,undefined
|
15
|
+
# slower, regular build, allow lldb
|
16
|
+
#CFLAGS = -g -std=c99 -Wall -Wextra -MMD -MP
|
17
|
+
#LDFLAGS =
|
18
|
+
|
19
|
+
|
20
|
+
#### OS specific ####
|
21
|
+
OS := $(shell uname)
|
22
|
+
|
23
|
+
ifeq ($(OS),Darwin)
|
24
|
+
# macOS flags
|
25
|
+
CFLAGS = $(CFLAGS_COMMON) -fPIC -mmacosx-version-min=11.0 -arch arm64
|
26
|
+
LDFLAGS = $(LDFLAGS_COMMON)
|
27
|
+
else ifeq ($(OS),Linux)
|
28
|
+
# Linux flags
|
29
|
+
CFLAGS = $(CFLAGS_COMMON) -fPIC
|
30
|
+
LDFLAGS = $(LDFLAGS_COMMON)
|
31
|
+
else ifeq '$(findstring ;,$(PATH))' ';'
|
32
|
+
# windows flags
|
33
|
+
CFLAGS = $(CFLAGS_COMMON) -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00
|
34
|
+
LDFLAGS = $(LDFLAGS_COMMON)
|
35
|
+
else
|
36
|
+
# Default fallback
|
37
|
+
CFLAGS = $(CFLAGS_COMMON) -fPIC
|
38
|
+
LDFLAGS = $(LDFLAGS_COMMON)
|
39
|
+
endif
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
#### Targets and Commands ####
|
44
|
+
|
45
|
+
# Source and object files
|
46
|
+
SRC = sim_funcs.c model.c patch.c
|
47
|
+
RUNNER_SRC = runner.c
|
48
|
+
OBJ = $(SRC:.c=.o)
|
49
|
+
RUNNER_OBJ = $(RUNNER_SRC:.c=.o)
|
50
|
+
RUNNER_DEPS = $(RUNNER_OBJ:.o=.d)
|
51
|
+
DEPS = $(OBJ:.o=.d) $(RUNNER_DEPS)
|
52
|
+
|
53
|
+
# Executable name
|
54
|
+
TEST = runner
|
55
|
+
ifeq '$(findstring ;,$(PATH))' ';'
|
56
|
+
# windows
|
57
|
+
SHARED_LIB = piegyc.dll
|
58
|
+
else
|
59
|
+
SHARED_LIB = piegyc.so
|
60
|
+
endif
|
61
|
+
|
62
|
+
|
63
|
+
# Default target
|
64
|
+
all: $(SHARED_LIB) $(TEST)
|
65
|
+
|
66
|
+
# test file
|
67
|
+
test: $(TEST)
|
68
|
+
|
69
|
+
# shared library
|
70
|
+
so: $(SHARED_LIB)
|
71
|
+
|
72
|
+
# Link the final binary
|
73
|
+
$(TEST): $(OBJ) $(RUNNER_OBJ)
|
74
|
+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
75
|
+
|
76
|
+
# Shared library target
|
77
|
+
$(SHARED_LIB): $(OBJ)
|
78
|
+
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^
|
79
|
+
|
80
|
+
# Compile source files to object files
|
81
|
+
%.o: %.c
|
82
|
+
$(CC) $(CFLAGS) -c $< -o $@
|
83
|
+
|
84
|
+
# Clean build files
|
85
|
+
clean:
|
86
|
+
rm -f $(OBJ) $(RUNNER_OBJ) $(TEST) $(SHARED_LIB) $(DEPS)
|
87
|
+
|
88
|
+
# Rebuild target: clean then all
|
89
|
+
re: clean all
|
90
|
+
|
91
|
+
# Include auto-generated dependency files
|
92
|
+
-include $(DEPS)
|
93
|
+
|
94
|
+
.PHONY: all clean re test so
|
95
|
+
|
96
|
+
|
97
|
+
|
piegy/C_core/model.c
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
/**
|
2
|
+
* This .c includes the model struct and "member functions"
|
3
|
+
* that correponds to patch class in piegy.model module
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdbool.h>
|
10
|
+
|
11
|
+
#include "model.h"
|
12
|
+
|
13
|
+
|
14
|
+
bool mod_init(model_t* mod, size_t N, size_t M,
|
15
|
+
double maxtime, double record_itv, size_t sim_time, bool boundary,
|
16
|
+
const uint32_t* I, const double* X, const double* P,
|
17
|
+
int32_t print_pct, int32_t seed) {
|
18
|
+
|
19
|
+
mod->N = N;
|
20
|
+
mod->M = M;
|
21
|
+
mod->maxtime = maxtime;
|
22
|
+
mod->record_itv = record_itv;
|
23
|
+
mod->sim_time = sim_time;
|
24
|
+
mod->boundary = boundary;
|
25
|
+
mod->print_pct = print_pct;
|
26
|
+
mod->seed = seed;
|
27
|
+
|
28
|
+
size_t NM = N * M;
|
29
|
+
|
30
|
+
// I, X, P
|
31
|
+
mod->I = (uint32_t*) malloc(sizeof(uint32_t) * NM * 2);
|
32
|
+
mod->X = (double*) malloc(sizeof(double) * NM * 4);
|
33
|
+
mod->P = (double*) malloc(sizeof(double) * NM * 6);
|
34
|
+
|
35
|
+
if (!mod->I || !mod->X || !mod->P) return false;
|
36
|
+
|
37
|
+
memcpy(mod->I, I, sizeof(uint32_t) * NM * 2);
|
38
|
+
memcpy(mod->X, X, sizeof(double) * NM * 4);
|
39
|
+
memcpy(mod->P, P, sizeof(double) * NM * 6);
|
40
|
+
|
41
|
+
// Data
|
42
|
+
mod->data_empty = true;
|
43
|
+
mod->max_record = (size_t)(mod->maxtime / mod->record_itv);
|
44
|
+
mod->arr_size = NM * mod->max_record;
|
45
|
+
mod->compress_itv = 1;
|
46
|
+
|
47
|
+
mod->U1d = (double*) calloc(mod->arr_size, sizeof(double));
|
48
|
+
mod->V1d = (double*) calloc(mod->arr_size, sizeof(double));
|
49
|
+
mod->Upi_1d = (double*) calloc(mod->arr_size, sizeof(double));
|
50
|
+
mod->Vpi_1d = (double*) calloc(mod->arr_size, sizeof(double));
|
51
|
+
|
52
|
+
if (!mod->U1d || !mod->V1d || !mod->Upi_1d || !mod->Vpi_1d) {
|
53
|
+
fprintf(stdout, "Error: allocating memory in mod_init.\n");
|
54
|
+
fflush(stdout);
|
55
|
+
exit(EXIT_FAILURE);
|
56
|
+
}
|
57
|
+
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
void mod_free(model_t* mod) {
|
64
|
+
if (!mod) return;
|
65
|
+
|
66
|
+
free(mod->I);
|
67
|
+
free(mod->X);
|
68
|
+
free(mod->P);
|
69
|
+
free(mod->U1d);
|
70
|
+
free(mod->V1d);
|
71
|
+
free(mod->Upi_1d);
|
72
|
+
free(mod->Vpi_1d);
|
73
|
+
mod->I = NULL;
|
74
|
+
mod->X = mod->P = mod->U1d = mod->V1d = mod->Upi_1d = mod->Vpi_1d = NULL;
|
75
|
+
|
76
|
+
free(mod);
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
void mod_free_py(model_t* mod) {
|
81
|
+
// free function for python
|
82
|
+
|
83
|
+
if (!mod) return;
|
84
|
+
if (mod->I) { free(mod->I); }
|
85
|
+
if (mod->X) { free(mod->X); }
|
86
|
+
if (mod->P) { free(mod->P); }
|
87
|
+
if (mod->U1d) { free(mod->U1d); }
|
88
|
+
if (mod->V1d) { free(mod->V1d); }
|
89
|
+
if (mod->Upi_1d) { free(mod->Upi_1d); }
|
90
|
+
if (mod->Vpi_1d) { free(mod->Vpi_1d); }
|
91
|
+
// if (mod) { free(mod); }
|
92
|
+
|
93
|
+
mod->I = NULL;
|
94
|
+
mod->X = mod->P = mod->U1d = mod->V1d = mod->Upi_1d = mod->Vpi_1d = NULL;
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
void calculate_ave(model_t* mod) {
|
99
|
+
if (mod->sim_time == 1) return;
|
100
|
+
|
101
|
+
for (size_t i = 0; i < mod->arr_size; i++) {
|
102
|
+
mod->U1d[i] /= mod->sim_time;
|
103
|
+
mod->V1d[i] /= mod->sim_time;
|
104
|
+
mod->Upi_1d[i] /= mod->sim_time;
|
105
|
+
mod->Vpi_1d[i] /= mod->sim_time;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
piegy/C_core/model.h
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
* This .h includes the model struct and "member functions"
|
3
|
+
* that correpond to patch class in piegy.model module
|
4
|
+
*/
|
5
|
+
#ifndef MODEL_H
|
6
|
+
#define MODEL_H
|
7
|
+
|
8
|
+
#include <stdbool.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <stdint.h>
|
11
|
+
|
12
|
+
|
13
|
+
typedef struct model_t {
|
14
|
+
size_t N;
|
15
|
+
size_t M;
|
16
|
+
double maxtime;
|
17
|
+
double record_itv;
|
18
|
+
size_t sim_time;
|
19
|
+
|
20
|
+
bool boundary;
|
21
|
+
|
22
|
+
// 3D arrays flattened to 1D for C
|
23
|
+
// Sizes: N * M * 2, N * M * 4, N * M * 6
|
24
|
+
uint32_t* I;
|
25
|
+
double* X;
|
26
|
+
double* P;
|
27
|
+
|
28
|
+
int32_t print_pct;
|
29
|
+
int32_t seed; // -1 for none
|
30
|
+
|
31
|
+
// vars for data storage
|
32
|
+
bool data_empty;
|
33
|
+
size_t max_record;
|
34
|
+
size_t arr_size; // size of U, V, U_pi, V_pi, equals N * M * max_record
|
35
|
+
uint32_t compress_itv;
|
36
|
+
double* U1d;
|
37
|
+
double* V1d;
|
38
|
+
double* Upi_1d;
|
39
|
+
double* Vpi_1d;
|
40
|
+
} model_t;
|
41
|
+
|
42
|
+
|
43
|
+
bool mod_init(model_t* mod, size_t N, size_t M,
|
44
|
+
double maxtime, double record_itv, size_t sim_time, bool boundary,
|
45
|
+
const uint32_t* I, const double* X, const double* P,
|
46
|
+
int32_t print_pct, int32_t seed);
|
47
|
+
void mod_free(model_t* mod);
|
48
|
+
void mod_free_py(model_t* mod);
|
49
|
+
void calculate_ave(model_t* mod);
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
#endif // MODEL_H
|
54
|
+
|
piegy/C_core/patch.c
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* This .c includes the patch struct and "member functions"
|
3
|
+
* that correponds to patch class in piegy.model module
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "patch.h"
|
7
|
+
|
8
|
+
void patch_init(patch_t* p, uint32_t U, uint32_t V, size_t i, size_t j) {
|
9
|
+
if (p == NULL) return;
|
10
|
+
p->i = i;
|
11
|
+
p->j = j;
|
12
|
+
|
13
|
+
p->U = U;
|
14
|
+
p->V = V;
|
15
|
+
p->U_pi = 0.0;
|
16
|
+
p->V_pi = 0.0;
|
17
|
+
|
18
|
+
for (size_t i = 0; i < 4; i++) {
|
19
|
+
p->U_weight[i] = 0.0;
|
20
|
+
p->V_weight[i] = 0.0;
|
21
|
+
p->pi_death_rates[i] = 0.0;
|
22
|
+
}
|
23
|
+
for (size_t i = 0; i < 8; i++) {
|
24
|
+
p->mig_rates[i] = 0.0;
|
25
|
+
}
|
26
|
+
p->sum_U_weight = 0.0;
|
27
|
+
p->sum_V_weight = 0.0;
|
28
|
+
p->sum_pi_death_rates = 0.0;
|
29
|
+
p->sum_mig_rates = 0.0;
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
void set_nb(patch_t* world, size_t* nb_start, size_t ij, size_t NM) {
|
34
|
+
// nb_start is the where patch ij's neighbor indices start
|
35
|
+
for (size_t k = 0; k < 4; k++) {
|
36
|
+
if (nb_start[k] != NM) {
|
37
|
+
// neighbor is valid
|
38
|
+
world[ij].nb[k] = &world[nb_start[k]];
|
39
|
+
} else {
|
40
|
+
world[ij].nb[k] = NULL;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
piegy/C_core/patch.h
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* This .h includes the patch struct and "member functions"
|
3
|
+
* that correponds to patch class in piegy.model module
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef PATCH_H
|
7
|
+
#define PATCH_H
|
8
|
+
|
9
|
+
#include <math.h>
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdint.h>
|
12
|
+
#include <stdbool.h>
|
13
|
+
|
14
|
+
|
15
|
+
// patch_t has size 33 * sizeof(size_t)
|
16
|
+
#define SIZEOF_PATCH_T (uint32_t) (sizeof(patch_t) / sizeof(size_t))
|
17
|
+
|
18
|
+
typedef struct patch_t {
|
19
|
+
size_t i;
|
20
|
+
size_t j;
|
21
|
+
|
22
|
+
uint32_t U;
|
23
|
+
uint32_t V;
|
24
|
+
double U_pi;
|
25
|
+
double V_pi;
|
26
|
+
|
27
|
+
struct patch_t* nb[4];
|
28
|
+
double U_weight[4]; // stores migration weight of each of the 4 neighbors
|
29
|
+
double V_weight[4];
|
30
|
+
double sum_U_weight; // sum of U_weight
|
31
|
+
double sum_V_weight;
|
32
|
+
double pi_death_rates[4];
|
33
|
+
double mig_rates[8];
|
34
|
+
double sum_pi_death_rates;
|
35
|
+
double sum_mig_rates;
|
36
|
+
} patch_t;
|
37
|
+
|
38
|
+
// in .c
|
39
|
+
void patch_init(patch_t* p, uint32_t U, uint32_t V, size_t i, size_t j);
|
40
|
+
void set_nb(patch_t* world, size_t* nb_start, size_t ij, size_t NM);
|
41
|
+
|
42
|
+
#endif // PATCH_H
|
43
|
+
|
piegy/C_core/piegyc.h
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
// piegyc.h
|
2
|
+
// piegy simulation module written in c
|
3
|
+
#ifndef PIEGYC_H
|
4
|
+
#define PIEGYC_H
|
5
|
+
|
6
|
+
#include <stdbool.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
|
9
|
+
|
10
|
+
typedef struct model_t {
|
11
|
+
size_t N;
|
12
|
+
size_t M;
|
13
|
+
double maxtime;
|
14
|
+
double record_itv;
|
15
|
+
size_t sim_time;
|
16
|
+
|
17
|
+
bool boundary;
|
18
|
+
|
19
|
+
// 3D arrays flattened to 1D for C
|
20
|
+
// Sizes: N * M * 2, N * M * 4, N * M * 6
|
21
|
+
uint32_t* I;
|
22
|
+
double* X;
|
23
|
+
double* P;
|
24
|
+
|
25
|
+
int32_t print_pct;
|
26
|
+
int32_t seed; // -1 for none
|
27
|
+
|
28
|
+
// vars for data storage
|
29
|
+
bool data_empty;
|
30
|
+
size_t max_record;
|
31
|
+
size_t arr_size; // size of U, V, U_pi, V_pi, equals N * M * max_record
|
32
|
+
uint32_t compress_itv;
|
33
|
+
double* U1d;
|
34
|
+
double* V;
|
35
|
+
double* U_pi;
|
36
|
+
double* V_pi;
|
37
|
+
} model_t;
|
38
|
+
|
39
|
+
bool mod_init(model_t* mod, size_t N, size_t M,
|
40
|
+
double maxtime, double record_itv, size_t sim_time, bool boundary,
|
41
|
+
const uint32_t* I, const double* X, const double* P,
|
42
|
+
int32_t print_pct, int32_t seed);
|
43
|
+
void mod_free_py(model_t* mod);
|
44
|
+
|
45
|
+
void run(model_t* mod, char* message, size_t msg_len);
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
#endif // PIEGYC_H
|
Binary file
|
piegy/C_core/runner.c
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#include <stdbool.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <stdint.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
#include "model.h"
|
7
|
+
#include "patch.h"
|
8
|
+
#include "sim_funcs.h"
|
9
|
+
|
10
|
+
|
11
|
+
int main() {
|
12
|
+
size_t N = 1;
|
13
|
+
size_t M = 100;
|
14
|
+
double maxtime = 1000;
|
15
|
+
double record_itv = 0.1;
|
16
|
+
size_t sim_time = 3;
|
17
|
+
bool boundary = true;
|
18
|
+
uint32_t I_single[2] = {200, 100};
|
19
|
+
double X_single[4] = {-1, 4, 0, 2};
|
20
|
+
double P_single[6] = {0.5, 0.5, 1, 1, 0.001, 0.001};
|
21
|
+
int32_t print_pct = 1;
|
22
|
+
int32_t seed = 36; // -1 for None
|
23
|
+
|
24
|
+
uint32_t I[N * M * 2];
|
25
|
+
double X[N * M * 4];
|
26
|
+
double P[N * M * 6];
|
27
|
+
|
28
|
+
//printf("sizeof(patch_t) = %zu bytes\n", sizeof(patch_t));
|
29
|
+
size_t ij = 0;
|
30
|
+
for (size_t i = 0; i < N; i++) {
|
31
|
+
for (size_t j = 0; j < M; j++) {
|
32
|
+
I[ij * 2] = I_single[0];
|
33
|
+
I[ij * 2 + 1] = I_single[1];
|
34
|
+
|
35
|
+
for (size_t k = 0; k < 4; k++) {
|
36
|
+
X[ij * 4 + k] = X_single[k];
|
37
|
+
}
|
38
|
+
for (size_t k = 0; k < 6; k++) {
|
39
|
+
P[ij * 6 + k] = P_single[k];
|
40
|
+
}
|
41
|
+
++ij;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
model_t* mod = malloc(sizeof(model_t));
|
46
|
+
mod_init(mod, N, M, maxtime, record_itv, sim_time, boundary, I, X, P, print_pct, seed);
|
47
|
+
|
48
|
+
char message[20] = ""; // writable buffer with enough space
|
49
|
+
run(mod, message, 20);
|
50
|
+
|
51
|
+
/*for (size_t i = 0; i < mod->max_record; i++) {
|
52
|
+
fprintf(stdout, "%f ", mod->U1d[i]);
|
53
|
+
}
|
54
|
+
fprintf(stdout, "\n");
|
55
|
+
for (size_t i = 0; i < mod->max_record; i++) {
|
56
|
+
fprintf(stdout, "%f ", mod->Upi_1d[i]);
|
57
|
+
}*/
|
58
|
+
mod_free(mod);
|
59
|
+
mod = NULL;
|
60
|
+
}
|
61
|
+
|