py-graspi 0.0.1.0__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.
- py_graspi-0.0.1.0/PKG-INFO +11 -0
- py_graspi-0.0.1.0/README.md +490 -0
- py_graspi-0.0.1.0/graspi_igraph/__init__.py +4 -0
- py_graspi-0.0.1.0/graspi_igraph/bugfix_descriptors.py +46 -0
- py_graspi-0.0.1.0/graspi_igraph/csvFileMaker.py +99 -0
- py_graspi-0.0.1.0/graspi_igraph/csvFileTest.py +55 -0
- py_graspi-0.0.1.0/graspi_igraph/descriptors.py +337 -0
- py_graspi-0.0.1.0/graspi_igraph/igraph_testing.py +638 -0
- py_graspi-0.0.1.0/graspi_igraph/simple-test.py +34 -0
- py_graspi-0.0.1.0/graspi_igraph/testFileMaker.py +46 -0
- py_graspi-0.0.1.0/graspi_igraph/tests.py +101 -0
- py_graspi-0.0.1.0/py_graspi.egg-info/PKG-INFO +11 -0
- py_graspi-0.0.1.0/py_graspi.egg-info/SOURCES.txt +16 -0
- py_graspi-0.0.1.0/py_graspi.egg-info/dependency_links.txt +1 -0
- py_graspi-0.0.1.0/py_graspi.egg-info/requires.txt +3 -0
- py_graspi-0.0.1.0/py_graspi.egg-info/top_level.txt +1 -0
- py_graspi-0.0.1.0/setup.cfg +4 -0
- py_graspi-0.0.1.0/setup.py +18 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: py-graspi
|
|
3
|
+
Version: 0.0.1.0
|
|
4
|
+
Summary: Utilize Python-igraph to produce similar functionality as GraSPI
|
|
5
|
+
Author: Wenqi Zheng
|
|
6
|
+
Author-email: wenqizhe@buffalo.edu
|
|
7
|
+
Classifier: Programming Language :: Python
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Requires-Dist: igraph
|
|
10
|
+
Requires-Dist: matplotlib
|
|
11
|
+
Requires-Dist: numpy
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
# py-graspi
|
|
2
|
+
|
|
3
|
+
Python-Igraph is a graph-based library contender for the library that works with the GraSPI package.
|
|
4
|
+
|
|
5
|
+
This repository contains the implementation to test basic algorithm requirements that need to be met for this package to work similarly to GraSPI.
|
|
6
|
+
The basic algorithm requirements include:
|
|
7
|
+
- Construction of graphs
|
|
8
|
+
- Graph Filtering
|
|
9
|
+
- Determine the number of connected components
|
|
10
|
+
- Determine the shortest path from the bottom boundary to all black vertices until the white vertices are met
|
|
11
|
+
- Graph visualization
|
|
12
|
+
- Computation of Descriptors
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
First, you'd need to clone the repo by running the following command in your command line:
|
|
16
|
+
```
|
|
17
|
+
git clone git@github.com:wenqizheng326/graspi_igraph.git
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
**Note: You'd need git installed on your system first**
|
|
21
|
+
<br />
|
|
22
|
+
<br />
|
|
23
|
+
If you do not have git installed or run into issues with git, please visit: https://github.com/git-guides/install-git
|
|
24
|
+
<br />
|
|
25
|
+
<br />
|
|
26
|
+
Next, you'd need to navigate to the cloned repo using terminal. An example would be:
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
cd /path/graspi_igraph
|
|
30
|
+
```
|
|
31
|
+
First, make sure you're on the memoryFix branch of the repo by running
|
|
32
|
+
```
|
|
33
|
+
git checkout memoryFix
|
|
34
|
+
```
|
|
35
|
+
Once navigated to the branch, downloads needed can be found in requirements.txt and can be installed by:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
pip install -r requirements.txt
|
|
39
|
+
```
|
|
40
|
+
**Note: you must have Python and pip installed onto your system**
|
|
41
|
+
<br />
|
|
42
|
+
<br />
|
|
43
|
+
If you do not have Python installed, please visit: https://www.python.org/downloads/
|
|
44
|
+
<br />
|
|
45
|
+
<br />
|
|
46
|
+
If you do not have pip installed or are running into issues with pip, please visit: https://pip.pypa.io/en/stable/installation/
|
|
47
|
+
<br />
|
|
48
|
+
<br />
|
|
49
|
+
If there are any other issues with installation, please visit: https://python.igraph.org/en/stable/
|
|
50
|
+
|
|
51
|
+
## Running memory tests
|
|
52
|
+
To run memory tests, run the following command in terminal:
|
|
53
|
+
```
|
|
54
|
+
python main.py n dimension function
|
|
55
|
+
```
|
|
56
|
+
**Make sure of the following:**
|
|
57
|
+
- Replace "n" with the size of the graph you want. Note: n should be between 1-1000 for 2D graphs and 1-100 for 3D graphs
|
|
58
|
+
- Replace "dimension" with 2D or 3D to specify if you want a 2D or 3D graph
|
|
59
|
+
- Replace "function" with either generate, filter, or shortest_path, to choose which function you want to test memory for
|
|
60
|
+
|
|
61
|
+
<br />**An example of a correct command would be:**
|
|
62
|
+
```
|
|
63
|
+
python main.py 10 2D generate
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
## Outputs
|
|
67
|
+
After running this command, you should see
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Generating results
|
|
71
|
+
```
|
|
72
|
+
Followed by the memory usage and runtime results after some time.
|
|
73
|
+
<br />
|
|
74
|
+
<br />
|
|
75
|
+
The following will print:
|
|
76
|
+
```
|
|
77
|
+
Completed
|
|
78
|
+
```
|
|
79
|
+
To know that the tests have been completed
|
|
80
|
+
## To Test Algorithms
|
|
81
|
+
|
|
82
|
+
To **generate graphs**, call the generateGraph(_file_) function which takes in a input-file name
|
|
83
|
+
- returns a graph
|
|
84
|
+
```
|
|
85
|
+
ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To **filter graphs**, call filterGraph(_graph_) function which takes in a graph object
|
|
89
|
+
- can pass a graph generated by generateGraph(_file_)
|
|
90
|
+
- returns a filtered graph
|
|
91
|
+
```
|
|
92
|
+
g = ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
93
|
+
fg = ig.filterGraph(g)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To **determine the connected components** of the filtered graph, call connected_components() function
|
|
97
|
+
```
|
|
98
|
+
print(fg.connected_components())
|
|
99
|
+
```
|
|
100
|
+
The number of connected components can be found by taking the length of the result produced by the connected_components function
|
|
101
|
+
```
|
|
102
|
+
print(len(fg.connected_components()))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The **shortest path** between some meta-vertices to all specified vertices calling the function shortest_path(_fiteredGraph_, _specifiedVertices_, _metaVertex_, _fileName_)
|
|
106
|
+
- stores the distance of the paths to from the _metaVertex_ to every single _specified Vertices_ in a text file called _fileName_
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
- the example below finds the shortest path between all black vertices to the blue meta-vertex and stores it in the text file, black_to_blue_paths.txt
|
|
110
|
+
```
|
|
111
|
+
ig.shortest_path(fg,'black','blue',"black_to_blue_paths.txt") #fg is a filtered graph object
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### To get list of descriptors (WZ)
|
|
115
|
+
|
|
116
|
+
A **descriptors stored in a dictionary** can be found by calling the function descriptors(_graph_)
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
ig.descriptors(g) # g is a graph object
|
|
120
|
+
```
|
|
121
|
+
A **list of descriptors in a text file** can be found by calling the function descriptorsToTxt(_dictionary_,_filename_)
|
|
122
|
+
```
|
|
123
|
+
ig.descriptorsToTxt(dict,"descriptors_list.txt")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### To visualize graphs
|
|
127
|
+
|
|
128
|
+
- for 2d graphs, call visual2D(_graph_)
|
|
129
|
+
```
|
|
130
|
+
g = ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
131
|
+
ig.visual2D(g)
|
|
132
|
+
```
|
|
133
|
+
- for 3d graphs, call visual3D(_graph_)
|
|
134
|
+
```
|
|
135
|
+
g = ig.generateGraph("3D-testFile/testFile-10-3D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
136
|
+
ig.visual3D(g)
|
|
137
|
+
Finally, the following message will be printed out:
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Testing from Command Line
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
\*\*\*First and foremost make sure you are in the py-graspi directory. If not you may run into some errors\*\*\*
|
|
144
|
+
|
|
145
|
+
In this GitHub Repo, all the tests are in the test directory. Furthermore, within this directory are two more directories: 2D-testFile and 3D-testFile.
|
|
146
|
+
Inside these directories, some files hold information about either 2d or 3d graphs based on the directory name.
|
|
147
|
+
When running from command lines you will need to know the complete pathname of the test file you are trying to run.
|
|
148
|
+
|
|
149
|
+
There are 2 type of input file formats: *.txt & *.graphe
|
|
150
|
+
### _*.txt input format:_
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
The command line input to run a graph creation for *.txt files will have the following format:
|
|
154
|
+
```
|
|
155
|
+
python graspi_igraph/igraph_testing.py {total pathname of test file} {2d or 3d}
|
|
156
|
+
```
|
|
157
|
+
If you have the same test directories as this GitHub Repo you should be able to run the following command line argument to output a 2D 10x10 graph.
|
|
158
|
+
```
|
|
159
|
+
python graspi_igraph/igraph_testing.py graspi_igraph/tests/2D-testFile/testFile-10-2D.txt 2d
|
|
160
|
+
```
|
|
161
|
+
### _*.graphe input format:_
|
|
162
|
+
*.graphe input format is not that different, only extra parameter you need to input is a 'g' before the total pathname of the test file.
|
|
163
|
+
|
|
164
|
+
The command line input to run a graph creation for *.graphe files will have the following format:
|
|
165
|
+
````
|
|
166
|
+
python graspi_igraph/igraph_testing.py g {total pathname of test file} {2d or 3d}
|
|
167
|
+
````
|
|
168
|
+
If you have the same test directories as this GitHub Repo you should be able to run the following command line argument to output a 2D 4x3 graph.
|
|
169
|
+
```
|
|
170
|
+
python graspi_igraph/igraph_testing.py g graspi_igraph/tests/2D-testFile/data_4_3.graphe 2d
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
Python-Igraph is a graph-based library contender for the library that works with the GraSPI package.
|
|
175
|
+
|
|
176
|
+
This repository contains the implementation to test basic algorithm requirements that need to be met for this package to work similarly to GraSPI.
|
|
177
|
+
The basic algorithm requirements include:
|
|
178
|
+
- Construction of graphs
|
|
179
|
+
- Graph Filtering
|
|
180
|
+
- Determine the number of connected components
|
|
181
|
+
- Determine the shortest path from some meta-vertices to all specified vertices
|
|
182
|
+
- Provide a list of descriptors
|
|
183
|
+
- Graph visualization
|
|
184
|
+
|
|
185
|
+
## Installation
|
|
186
|
+
Download the packages found in requirements.txt after you have set up your virtual environment.
|
|
187
|
+
Cone the repo by:
|
|
188
|
+
```
|
|
189
|
+
git clone https://github.com/owodolab/py-graspi.git
|
|
190
|
+
```
|
|
191
|
+
**Note: You'd need git installed on your system first**
|
|
192
|
+
<br />
|
|
193
|
+
<br />
|
|
194
|
+
If you do not have git installed or run into issues with git, please visit: https://github.com/git-guides/install-git
|
|
195
|
+
<br />
|
|
196
|
+
<br />
|
|
197
|
+
Next, you'd need to navigate to the cloned repo using terminal. An example would be:
|
|
198
|
+
```
|
|
199
|
+
cd /path/py-graspi
|
|
200
|
+
```
|
|
201
|
+
Once navigated to the branch, access the following directory:
|
|
202
|
+
```
|
|
203
|
+
cd graspi_igraph
|
|
204
|
+
```
|
|
205
|
+
Next, the downloads needed can be found in requirements.txt and can be installed by:
|
|
206
|
+
```
|
|
207
|
+
pip install notebook
|
|
208
|
+
```
|
|
209
|
+
Install the graspi_igraph package by:
|
|
210
|
+
```
|
|
211
|
+
pip install graspi-igraph
|
|
212
|
+
```
|
|
213
|
+
Once installed, to utilize the package remember to import the package:
|
|
214
|
+
```
|
|
215
|
+
import graspi_igraph as ig
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Note: you must have Python and pip installed onto your system**
|
|
219
|
+
<br />
|
|
220
|
+
<br />
|
|
221
|
+
If you do not have Python installed, please visit: https://www.python.org/downloads/
|
|
222
|
+
<br />
|
|
223
|
+
<br />
|
|
224
|
+
If you do not have pip installed or are running into issues with pip, please visit: https://pip.pypa.io/en/stable/installation/
|
|
225
|
+
<br />
|
|
226
|
+
<br />
|
|
227
|
+
If there are any other issues with installation, please visit: https://python.igraph.org/en/stable/
|
|
228
|
+
|
|
229
|
+
## Running All 33 Morphologies Tests (JZ)
|
|
230
|
+
To run the morphologies tests, return to the previous directory of "/py-graspi" by running:
|
|
231
|
+
```
|
|
232
|
+
cd ..
|
|
233
|
+
```
|
|
234
|
+
Next, make sure you're on bash first by running:
|
|
235
|
+
```
|
|
236
|
+
bash
|
|
237
|
+
```
|
|
238
|
+
Next, run the following:
|
|
239
|
+
```
|
|
240
|
+
chmod +x run.sh
|
|
241
|
+
```
|
|
242
|
+
Finally, run the following:
|
|
243
|
+
```
|
|
244
|
+
./run.sh <file_type>
|
|
245
|
+
```
|
|
246
|
+
Substitute <file_type> with either txt or pdf for the desired output type.
|
|
247
|
+
## 33 Morphologies Output (JZ)
|
|
248
|
+
After running the command, the automatic report generation will begin.
|
|
249
|
+
<br />
|
|
250
|
+
<br />
|
|
251
|
+
The following will print when the report generation begins:
|
|
252
|
+
```
|
|
253
|
+
Generating PDF (If on pdf mode)
|
|
254
|
+
Generating Text Files
|
|
255
|
+
```
|
|
256
|
+
As the script is running, the following will print for which microstructure it is on
|
|
257
|
+
```
|
|
258
|
+
Executing <test_file>
|
|
259
|
+
```
|
|
260
|
+
After a few minutes, the following will print once the report has been created
|
|
261
|
+
```
|
|
262
|
+
Text Files Generated
|
|
263
|
+
PDF Generated (If on pdf mode)
|
|
264
|
+
```
|
|
265
|
+
## Viewing 33 Morphologies Output (JZ)
|
|
266
|
+
For text files, navigate to the results directory by using the following command:
|
|
267
|
+
```
|
|
268
|
+
cd graspi_igraph/results
|
|
269
|
+
```
|
|
270
|
+
Use the following command to view the list of text files generated:
|
|
271
|
+
```
|
|
272
|
+
ls
|
|
273
|
+
```
|
|
274
|
+
To view the result in each file, run the following command:
|
|
275
|
+
```
|
|
276
|
+
cat <result_file_name>
|
|
277
|
+
```
|
|
278
|
+
Replace <result_file_name> with any of the files outputted by "ls"
|
|
279
|
+
<br />
|
|
280
|
+
<br />
|
|
281
|
+
If using pdf mode, the pdf should automattically open upon completion.
|
|
282
|
+
<br />
|
|
283
|
+
<br />
|
|
284
|
+
If the pdf does not automatically pop up, use the following commands:
|
|
285
|
+
### On Windows
|
|
286
|
+
```
|
|
287
|
+
start graspi_igraph/test_results.pdf
|
|
288
|
+
```
|
|
289
|
+
### On MacOS
|
|
290
|
+
```
|
|
291
|
+
open graspi_igraph/test_results.pdf
|
|
292
|
+
```
|
|
293
|
+
### On Linux
|
|
294
|
+
```
|
|
295
|
+
evince graspi_igraph/test_results.pdf
|
|
296
|
+
```
|
|
297
|
+
If evince is not installed, run this first:
|
|
298
|
+
```
|
|
299
|
+
sudo apt install evince
|
|
300
|
+
```
|
|
301
|
+
## To Test Algorithms
|
|
302
|
+
|
|
303
|
+
To **generate graphs**, call the generateGraph(_file_) function which takes in a input-file name
|
|
304
|
+
- returns a graph and a bool of whether it's a 2D graph
|
|
305
|
+
```
|
|
306
|
+
ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
To **filter graphs**, call filterGraph(_graph_) function which takes in a graph object
|
|
310
|
+
- can pass a graph generated by generateGraph(_file_)
|
|
311
|
+
- returns a filtered graph
|
|
312
|
+
```
|
|
313
|
+
g, is_2D = ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
314
|
+
fg = ig.filterGraph(g)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
To **determine the connected components** of the filtered graph, call connected_components() function
|
|
318
|
+
```
|
|
319
|
+
print(ig.connectedComponents(fg))
|
|
320
|
+
```
|
|
321
|
+
The number of connected components can be found by taking the length of the result produced by the connected_components function
|
|
322
|
+
```
|
|
323
|
+
print(len(ig.connectedComponents(fg)))
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The **shortest path** between some meta-vertices to all specified vertices calling the function shortest_path(_fiteredGraph_, _specifiedVertices_, _metaVertex_, _fileName_)
|
|
327
|
+
- stores the distance of the paths to from the _metaVertex_ to every single _specified Vertices_ in a text file called _fileName_
|
|
328
|
+
|
|
329
|
+
Example:
|
|
330
|
+
- the example below finds the shortest path between all black vertices to the blue meta-vertex and stores it in the text file, black_to_blue_paths.txt
|
|
331
|
+
```
|
|
332
|
+
ig.shortest_path(fg,'black','blue',"black_to_blue_paths.txt") #fg is a filtered graph object
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### To get list of descriptors (WZ)
|
|
336
|
+
|
|
337
|
+
A **descriptors stored in a dictionary** can be found by calling the function descriptors(_graph_)
|
|
338
|
+
|
|
339
|
+
```
|
|
340
|
+
ig.descriptors(g) # g is a graph object
|
|
341
|
+
```
|
|
342
|
+
A **list of descriptors in a text file** can be found by calling the function descriptorsToTxt(_dictionary_,_filename_)
|
|
343
|
+
- _dict_ is a dictionary of descriptors that is returned by calling ig.descriptors(g)
|
|
344
|
+
```
|
|
345
|
+
ig.descriptorsToTxt(dict,"descriptors_list.txt")
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
To test if descriptors are computed correctly, you can run the following script in the terminal to check.
|
|
349
|
+
- make sure you are in the py-graspi directory after git cloning
|
|
350
|
+
- if not in directory, in the terminal, run the command
|
|
351
|
+
```
|
|
352
|
+
cd py-graspi
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
python graspi_igraph/simple-test.py graspi_igraph/data/data_0.5_2.2_001900.txt
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### To visualize graphs
|
|
360
|
+
|
|
361
|
+
To visualize graphs, call visualize(_graph_, _is_2D_)
|
|
362
|
+
- _graph_ is a graph object
|
|
363
|
+
- _is_2D_ is a bool of whether a graph is 2D, also a return value when _generateGraph()_ is called
|
|
364
|
+
```
|
|
365
|
+
g, is_2D = ig.generateGraph("2D-testFile/testFile-10-2D.txt") # utilizing the test file found in 2D-testFiles folder as an example
|
|
366
|
+
ig.visual2D(g, is_2D)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Testing from Command Line (Kevin)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
Now that we have cloned the REPO lets talk about testing.
|
|
373
|
+
|
|
374
|
+
\*\*\*First and foremost make sure you are in te py-graspi directory. If not you may run into some errors\*\*\*
|
|
375
|
+
|
|
376
|
+
In this GitHub Repo, all the tests are in the test directory. Furthermore, within this directory are two more directories: 2D-testFile and 3D-testFile.
|
|
377
|
+
Inside these directories, some files hold information about either 2d or 3d graphs based on the directory name.
|
|
378
|
+
When running from command lines you will need to know the complete pathname of the test file you are trying to run.
|
|
379
|
+
|
|
380
|
+
There are 2 type of input file formats: *.txt & *.graphe
|
|
381
|
+
### _*.txt input format:_
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
The command line input to run a graph creation for *.txt files will have the following format:
|
|
385
|
+
```
|
|
386
|
+
python graspi_igraph/igraph_testing.py {total pathname of test file}
|
|
387
|
+
```
|
|
388
|
+
If you have the same test directories as this GitHub Repo you should be able to run the following command line argument to output a 2D 10x10 graph.
|
|
389
|
+
```
|
|
390
|
+
python graspi_igraph/igraph_testing.py graspi_igraph/tests/2D-testFile/testFile-10-2D.txt
|
|
391
|
+
```
|
|
392
|
+
### _*.graphe input format:_
|
|
393
|
+
*.graphe input format is not that different, only extra parameter you need to input is a 'g' before the total pathname of the test file.
|
|
394
|
+
|
|
395
|
+
The command line input to run a graph creation for *.graphe files will have the following format:
|
|
396
|
+
````
|
|
397
|
+
python graspi_igraph/igraph_testing.py -g {total pathname of test file}
|
|
398
|
+
````
|
|
399
|
+
If you have the same test directories as this GitHub Repo you should be able to run the following command line argument to output a 2D 4x3 graph.
|
|
400
|
+
```
|
|
401
|
+
python graspi_igraph/igraph_testing.py g graspi_igraph/tests/2D-testFile/data_4_3.graphe
|
|
402
|
+
```
|
|
403
|
+
### _Running with Periodicity:_
|
|
404
|
+
We include the option of running any test case with periodicity turned on ONLY for *.txt input files. This
|
|
405
|
+
is done with an added '-p' parameter. This parameter is added first before inputting the test case
|
|
406
|
+
format.
|
|
407
|
+
|
|
408
|
+
For example, for *.txt cases with periodicity turned on will look like the following:
|
|
409
|
+
```
|
|
410
|
+
python graspi_igraph/igraph_testing.py -p {total pathname of test file}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
To test this out run the example test case above but with the added '-p' parameter
|
|
414
|
+
to turn periodicity on.
|
|
415
|
+
|
|
416
|
+
## Generate and Run Files for py-graspi API (ML)
|
|
417
|
+
In order to generate an API using sphinx, you need to follow the installation of py-graspi:
|
|
418
|
+
|
|
419
|
+
Cloning the repository:
|
|
420
|
+
```
|
|
421
|
+
git clone https://github.com/owodolab/py-graspi.git
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
**Make sure your current directory is py-graspi**
|
|
425
|
+
|
|
426
|
+
In order to create an API with sphinx, you need to download sphinx with this command in the command line interface:
|
|
427
|
+
```
|
|
428
|
+
pip install sphinx
|
|
429
|
+
```
|
|
430
|
+
Additional dependencies needed for installed Sphinx Extension:
|
|
431
|
+
```
|
|
432
|
+
pip install sphinxcontrib-details-directive
|
|
433
|
+
```
|
|
434
|
+
Provides additional details (dropdowns) for each submodle listed.
|
|
435
|
+
```
|
|
436
|
+
pip install sphinx_rtd_theme
|
|
437
|
+
```
|
|
438
|
+
Uses the rtf theme for the API
|
|
439
|
+
```
|
|
440
|
+
pip install --upgrade setuptools
|
|
441
|
+
```
|
|
442
|
+
Used by python to handle resources and files
|
|
443
|
+
|
|
444
|
+
In the command line interface, run this command:
|
|
445
|
+
```
|
|
446
|
+
sphinx-build -b html ./docs/source/ ./docs/
|
|
447
|
+
```
|
|
448
|
+
* **sphinx-build**: This is the main command for building Sphinx documentation. It generates documentation from reStructuredText (.rst) or Markdown (.md) source files.
|
|
449
|
+
* **-b html**: This specifies the output format. Here, -b html tells Sphinx to build the documentation in HTML format, which is typically used for web-based documentation.
|
|
450
|
+
* **./docs/source/**: This is the path to the source directory where Sphinx looks for the documentation source files. In this example, it’s in the source subdirectory inside docs.
|
|
451
|
+
* **./docs/**: This is the output directory where the built HTML files will be saved. In this example, it’s the main docs folder. After running this command, you’ll find the generated HTML files here.
|
|
452
|
+
|
|
453
|
+
In order to see the py-graspi API, run this command in the command line interface:
|
|
454
|
+
|
|
455
|
+
**FOR WINDOWS:**
|
|
456
|
+
```
|
|
457
|
+
start docs/index.html
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**FOR MACOS:**
|
|
461
|
+
```
|
|
462
|
+
open docs/index.html
|
|
463
|
+
```
|
|
464
|
+
This would create a local view. You can see the official API on Github pages at: https://owodolab.github.io/py-graspi/
|
|
465
|
+
|
|
466
|
+
## 2D & 3D Morphologies Tests
|
|
467
|
+
To run the 2d and 3d morphologies you will need to setup notebook and pip install the graspi_igraph package.
|
|
468
|
+
|
|
469
|
+
First you will need to git clone the current repo, make sure that you are in the ""dev branch"":
|
|
470
|
+
```
|
|
471
|
+
git clone https://github.com/owodolab/py-graspi.git
|
|
472
|
+
```
|
|
473
|
+
Then, you will need to install the igraph package:
|
|
474
|
+
```
|
|
475
|
+
pip install graspi-igraph
|
|
476
|
+
```
|
|
477
|
+
Install jupyter notebook in order to view the test file:
|
|
478
|
+
```
|
|
479
|
+
pip install notebook
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
Finally, you will be able to use the command:
|
|
483
|
+
```
|
|
484
|
+
jupyter notebook
|
|
485
|
+
```
|
|
486
|
+
This will bring you into the testing filing on jupyter.
|
|
487
|
+
Navigate to the directory 3d_2d_tests.
|
|
488
|
+
Navigate to the file graspi_igraph_notebook.ipynb.
|
|
489
|
+
|
|
490
|
+
On this file you will be able to run and view the 2d and 3d morphologies for subtask 4, card 104.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import igraph_testing as ig
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
from mpl_toolkits.mplot3d import Axes3D
|
|
4
|
+
import numpy as np
|
|
5
|
+
import os
|
|
6
|
+
import descriptors
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
|
|
11
|
+
filename = sys.argv[1]
|
|
12
|
+
# dimension = sys.argv[2]
|
|
13
|
+
graph_type = sys.argv[2]
|
|
14
|
+
functionality = sys.argv[3]
|
|
15
|
+
|
|
16
|
+
g,is_2D = ig.generateGraph(filename)
|
|
17
|
+
fg = ig.filterGraph(g)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if functionality == 'visuals':
|
|
21
|
+
if is_2D == True:
|
|
22
|
+
if graph_type == 'g':
|
|
23
|
+
ig.visual2D(g,'graph')
|
|
24
|
+
print("Plot displayed.")
|
|
25
|
+
if graph_type == 'fg':
|
|
26
|
+
ig.visual2D(fg,'filtered')
|
|
27
|
+
print("Plot displayed.")
|
|
28
|
+
else:
|
|
29
|
+
if graph_type == 'g':
|
|
30
|
+
ig.visual3D(g)
|
|
31
|
+
if graph_type == 'fg':
|
|
32
|
+
ig.visual3D(fg)
|
|
33
|
+
|
|
34
|
+
if functionality == 'descriptors':
|
|
35
|
+
print(descriptors.descriptors(g))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if functionality == 'cc':
|
|
39
|
+
print(ig.connectedComponents(g))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == '__main__':
|
|
43
|
+
main()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from . import igraph_testing as ig
|
|
2
|
+
import time
|
|
3
|
+
import tracemalloc
|
|
4
|
+
import csv
|
|
5
|
+
|
|
6
|
+
def functionRuntime(count,function, *argv):
|
|
7
|
+
"""
|
|
8
|
+
Measures the average runtime of a function over a specified number of executions.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
count (int): The number of times to execute the function.
|
|
12
|
+
function (Callable): The function to measure the runtime for.
|
|
13
|
+
*argv: Arguments to be passed to the function.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
float: The average execution time in seconds across the `count` executions.
|
|
17
|
+
"""
|
|
18
|
+
totaltime = 0
|
|
19
|
+
|
|
20
|
+
for x in range(count):
|
|
21
|
+
startTime = time.time()
|
|
22
|
+
function(*argv)
|
|
23
|
+
endTime = time.time()
|
|
24
|
+
timeTaken = endTime - startTime
|
|
25
|
+
totaltime += timeTaken
|
|
26
|
+
|
|
27
|
+
avgExecution = totaltime / count
|
|
28
|
+
|
|
29
|
+
return avgExecution
|
|
30
|
+
|
|
31
|
+
def functionMemory(function, *argv):
|
|
32
|
+
"""
|
|
33
|
+
Measures the peak memory usage of a function during its execution.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
function (Callable): The function to measure memory usage for.
|
|
37
|
+
*argv: Arguments to be passed to the function.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
int: The memory used in bytes during the function's execution.
|
|
41
|
+
"""
|
|
42
|
+
tracemalloc.start()
|
|
43
|
+
function(*argv)
|
|
44
|
+
stats = tracemalloc.get_traced_memory()
|
|
45
|
+
tracemalloc.stop()
|
|
46
|
+
stats = stats[1] - stats[0]
|
|
47
|
+
|
|
48
|
+
return stats
|
|
49
|
+
|
|
50
|
+
def csvMaker(fileName, n, dim, count, graphGen, graphGenPar,graphFilt, graphFiltPar,shortPath, shortPathPar):
|
|
51
|
+
"""
|
|
52
|
+
Runs multiple graph-related functions, records their runtime and memory usage,
|
|
53
|
+
and stores the results in a CSV file.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
fileName (str): The name of the CSV file to write results to.
|
|
57
|
+
n (int): The base size parameter of the graph.
|
|
58
|
+
dim (int): The dimension to compute the total nodes as n^dim.
|
|
59
|
+
count (int): The number of times to run each function for benchmarking.
|
|
60
|
+
graphGen (Callable): Function to generate a graph.
|
|
61
|
+
graphGenPar (tuple): Parameters for the graph generation function.
|
|
62
|
+
graphFilt (Callable): Function to filter the graph.
|
|
63
|
+
graphFiltPar (tuple): Parameters for the graph filtering function.
|
|
64
|
+
shortPath (Callable): Function to compute the shortest path in the graph.
|
|
65
|
+
shortPathPar (tuple): Parameters for the shortest path function.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
None: The function writes results to the specified CSV file.
|
|
69
|
+
"""
|
|
70
|
+
row = [n,(n**dim)]
|
|
71
|
+
totalTime = 0
|
|
72
|
+
totalMem = 0
|
|
73
|
+
|
|
74
|
+
graphGenRuntime = functionRuntime(count,graphGen,*graphGenPar)
|
|
75
|
+
graphFiltRuntime = functionRuntime(count,graphFilt,*graphFiltPar)
|
|
76
|
+
shortPathRuntime = functionRuntime(count,shortPath,*shortPathPar)
|
|
77
|
+
|
|
78
|
+
totalTime = graphGenRuntime + graphFiltRuntime + shortPathRuntime
|
|
79
|
+
totalTime = round(totalTime,20)
|
|
80
|
+
|
|
81
|
+
graphGenMem = functionMemory(graphGen,*graphGenPar)
|
|
82
|
+
graphFiltMem = functionMemory(graphFilt,*graphFiltPar)
|
|
83
|
+
shortPathMem = functionMemory(shortPath,*shortPathPar)
|
|
84
|
+
|
|
85
|
+
totalMem = graphGenMem + graphFiltMem + shortPathMem
|
|
86
|
+
totalMem = round(totalMem,20)
|
|
87
|
+
|
|
88
|
+
row.append(graphGenRuntime)
|
|
89
|
+
row.append(graphFiltRuntime)
|
|
90
|
+
row.append(shortPathRuntime)
|
|
91
|
+
row.append(totalTime)
|
|
92
|
+
row.append(graphGenMem)
|
|
93
|
+
row.append(graphFiltMem)
|
|
94
|
+
row.append(shortPathMem)
|
|
95
|
+
row.append(totalMem)
|
|
96
|
+
|
|
97
|
+
with open(fileName, 'a', newline = "\n") as file:
|
|
98
|
+
writer = csv.writer(file)
|
|
99
|
+
writer.writerow(row)
|