Skip to content

Commit 5d32812

Browse files
committed
Removed main.cpp; changed naming and made performance testing work with current code
1 parent 2b7fd08 commit 5d32812

File tree

5 files changed

+116
-190
lines changed

5 files changed

+116
-190
lines changed

genGrouper/main.cpp

Lines changed: 0 additions & 128 deletions
This file was deleted.

genGrouper/utils.py

Lines changed: 93 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,88 @@
22
import typing as t
33
from copy import deepcopy
44

5-
def multi_to_pair(multi: int, max_multi: int) -> t.Tuple[int, int]:
6-
"""
7-
Convert a linear index `multi` to 2D coordinates (x, y) within a square grid.
8-
9-
Parameters:
10-
- multi (int): Linear index to be converted.
11-
- max_multi (int): Maximum allowed value for the linear index.
12-
13-
Returns:
14-
- Tuple[int, int]: Two-dimensional coordinates (x, y) within the grid.
15-
"""
16-
if 1 <= multi <= max_multi:
17-
# Calculate x and y values based on the input multi
18-
x = (multi - 1) % int(max_multi**.5) + 1
19-
y = (multi - 1) // int(max_multi**.5) + 1
20-
21-
x, y = x-1, y-1 # convert to 0-indexed
22-
return x, y
23-
else:
24-
raise ValueError("Input multi must be in the range 1 to max_multi.")
25-
26-
275
def run_performance_eval(
28-
nauty_path: str = "/Users/kieran/projects/genGrouper/packages/nauty2_8_8",
6+
nauty_path: str = "/Users/kieran/projects/molGrouper/packages/nauty2_8_8",
7+
node_defs = None,
298
n_runs: int = 3,
309
max_nodes: int = 6,
31-
max_ports: int = 4,
32-
n_colors: int = 3,
3310
verbose: bool = False
3411
):
3512
"""
3613
Run performance evaluation of the genGrouper generation featrure with growing sized graphs.
3714
"""
3815
import os
3916
import time
40-
from genGrouper.edge_coloring import process_nauty_vcolg_output
17+
from genGrouper import exhaustive_generate
4118
import random
19+
import itertools
20+
21+
if node_defs is None:
22+
raise ValueError("node_defs must be provided.")
23+
24+
# Time the performance of the generation algorithm
25+
performance = {combo : { n:[] for n in range(1, max_nodes + 1)} for combo in itertools.combinations(node_defs, len(node_defs) - 1)}
26+
for def_combo in performance:
27+
for n_nodes in range(1, max_nodes + 1):
28+
total_time = 0
29+
for i in range(n_runs):
30+
random.seed(0)
31+
start_time = time.time()
32+
space = exhaustive_generate(
33+
n_nodes,
34+
set(def_combo),
35+
nauty_path=nauty_path,
36+
input_file_path="",
37+
num_procs=16,
38+
verbose=verbose)
39+
end_time = time.time()
40+
total_time += end_time - start_time
41+
performance[def_combo][n_nodes].append(total_time)
42+
print(f"Number of generated graphs: {len(space)}")
43+
print("")
44+
# plot_performance(performance, max_nodes)
45+
return performance
46+
47+
def plot_performance(performance, max_nodes):
48+
import matplotlib.pyplot as plt
49+
import numpy as np
50+
import itertools
51+
52+
# Prepare data for the plot
53+
fig, ax = plt.subplots()
54+
55+
# Use a single colormap
56+
cmap = plt.get_cmap('inferno')
57+
norm = plt.Normalize()
58+
59+
# Iterate through the performance data to plot
60+
for i, combo in enumerate(performance):
61+
for n_nodes in performance[combo]:
62+
times = performance[combo][n_nodes]
63+
mean_time = np.mean(times)
64+
color = cmap(norm(mean_time))
65+
66+
ax.scatter(
67+
n_nodes,
68+
i,
69+
c=color
70+
)
71+
72+
ax.set_xlabel("Number of nodes")
73+
ax.set_ylabel("Node type combination")
74+
75+
# Adjust y-axis labels to display the node combinations
76+
ax.set_yticks(range(len(performance)))
77+
ax.set_yticklabels([str(combo) for combo in performance])
78+
79+
# Add the color bar
80+
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
81+
sm.set_array([]) # Only needed for the color bar
82+
plt.colorbar(sm, ax=ax, label='Mean Time (s)')
83+
84+
plt.savefig("performance.png")
85+
4286

43-
max_nodes = list(range(2, max_nodes))
44-
generate_random_ports = lambda max_ports: [str(i) for i in range(random.randint(1, max_ports))]
45-
node_types = {chr(i+65): generate_random_ports(max_ports) for i in range(n_colors)}
46-
47-
for n in max_nodes:
48-
total_time = 0
49-
for i in range(n_runs):
50-
os.system(f"{nauty_path}/geng {n} -ctf > /Users/kieran/projects/genGrouper/geng_out.txt")
51-
os.system(f"{nauty_path}/vcolg /Users/kieran/projects/genGrouper/geng_out.txt -T -m{n_colors} > vcolg_out.txt")
52-
# time the edge_coloring.py
53-
start = time.time()
54-
out = process_nauty_vcolg_output('/Users/kieran/projects/genGrouper/vcolg_out.txt', node_types, verbose=False)
55-
end = time.time()
56-
total_time += end - start
57-
print(f"Average time for {n} nodes: {total_time/n_runs}")
5887

5988
def convert_edges_to_nodetype(G):
6089
new_G = deepcopy(G)
@@ -71,3 +100,26 @@ def convert_edges_to_nodetype(G):
71100
new_G.edges[edge]['ports'][i] = (f'{srcnode_type}.{srcport}', f'{dstnode_type}.{dstport}')
72101

73102
return new_G
103+
104+
105+
def multi_to_pair(multi: int, max_multi: int) -> t.Tuple[int, int]:
106+
"""
107+
Convert a linear index `multi` to 2D coordinates (x, y) within a square grid.
108+
109+
Parameters:
110+
- multi (int): Linear index to be converted.
111+
- max_multi (int): Maximum allowed value for the linear index.
112+
113+
Returns:
114+
- Tuple[int, int]: Two-dimensional coordinates (x, y) within the grid.
115+
"""
116+
if 1 <= multi <= max_multi:
117+
# Calculate x and y values based on the input multi
118+
x = (multi - 1) % int(max_multi**.5) + 1
119+
y = (multi - 1) // int(max_multi**.5) + 1
120+
121+
x, y = x-1, y-1 # convert to 0-indexed
122+
return x, y
123+
else:
124+
raise ValueError("Input multi must be in the range 1 to max_multi.")
125+

performance_testing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from genGrouper.utils import run_performance_eval
2+
from genGrouper import Node
3+
4+
5+
node_defs = set()
6+
node_defs.add(Node(0, 'benzene', 'C1=CC=CC=C1', [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]))
7+
node_defs.add(Node(0, 'hydroxyl', 'O', [0], [0]))
8+
node_defs.add(Node(0, 'secondary_amine', 'N', [0,1], [0,0]))
9+
node_defs.add(Node(0, 'tertiary_amine', 'N', [0,1,2], [0,0,0]))
10+
node_defs.add(Node(0, 'alkene', 'C=C', [0], [0]))
11+
node_defs.add(Node(0, 'ester', 'C(=O)O', [0,1], [0,2]))
12+
13+
run_performance_eval(
14+
nauty_path="/raid6/homes/kierannp/projects/molGrouper/packages/nauty2_8_8",
15+
node_defs=node_defs,
16+
n_runs=3,
17+
max_nodes=4,
18+
verbose=False
19+
)

run_generation_eval.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

submission_scripts/cpu_submit_to_cluster.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#SBATCH --mail-type=end
44
#SBATCH --error=error-%J.err
55
#SBATCH --output=output-%J.out
6-
#SBATCH --job-name=cpu_gen
6+
#SBATCH --job-name=genGrouper
77
#SBATCH --nodes=1
88
#SBATCH --time=24:00:00
99
#SBATCH --partition=day-long-std
@@ -13,14 +13,8 @@
1313

1414
source /raid6/homes/kierannp/.bashrc
1515
module load anaconda/3.9
16-
conda activate molGPU
16+
conda activate pureGrouper
1717

18-
cd /raid6/homes/kierannp/foo/gpufoo/genGrouper/genGrouper/cpp_code/rdkit_cpu
19-
20-
rm -rf build
21-
mkdir build
22-
cd build
23-
cmake ..
24-
make
25-
./lineProcessor
18+
RUN_DIR=
2619

20+
python run_exhaustive_generation.py

0 commit comments

Comments
 (0)