-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add vf2 mapping functions #368
Conversation
This commit adds a new function vf2_mapping which is used to get the isomorphic node mapping between 2 graphs. It works in the same way as is_isomorphic() but instead of simply returning a boolean whether the graphs are isomorphic it returns the node id mapping from first to second for the matching.
Pull Request Test Coverage Report for Build 1034795520
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bug in the implementation when we use id_order=False
and we have to reindex the graph, e.g the final mapping in this example might be invalid.
temp = retworkx.generators.grid_graph(3, 3)
graph = rx.PyGraph()
dummy = graph.add_node(0)
graph.compose(temp, dict())
graph.remove_node(dummy)
second_graph = retworkx.generators.grid_graph(2, 2)
mapping = retworkx.graph_vf2_mapping(
graph, second_graph, subgraph=True, id_order=False
)
I suggested some changes that should fix this.
valid_mappings = [ | ||
{0: 0, 1: 1, 2: 2, 3: 3}, | ||
{0: 0, 1: 2, 2: 1, 3: 3}, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are more valid mappings since node 0
of graph
can be mapped to any node of second_graph
and still obtained an isomorphism
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there are a lot more valid mappings. I should rename this to expected_mappings
. I basically just ran tox -epy -- vf2 --until-failure
for like 500 iterations without failures to try and find an exhaustive set of mappings that this path could return. This isn't expected to be an exhaustive list of mappings, just those that I encountered when running the code. Unless you have a better suggestion on how to test this? Maybe just come up with an example that only has 1 possible mapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think there are that many, it should be 8 in total so in principle we could exhaustively list them. this might become a problem in the following test with subgraphs. maybe use a path graph that has just two possible mappings?
but honestly i'm ok to leave it as it is.
valid_mappings = [ | ||
{3: 2, 4: 3, 6: 0, 7: 1}, | ||
{3: 1, 4: 3, 6: 0, 7: 2}, | ||
{4: 3, 5: 1, 7: 2, 8: 0}, | ||
{0: 0, 1: 1, 3: 2, 4: 3}, | ||
{7: 1, 8: 0, 4: 3, 5: 2}, | ||
{5: 1, 2: 0, 1: 2, 4: 3}, | ||
{3: 1, 0: 0, 4: 3, 1: 2}, | ||
{1: 1, 2: 0, 4: 3, 5: 2}, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more possible mappings with same reasoning as above.
) | ||
self.assertEqual({0: 0, 3: 1}, mapping) | ||
|
||
def test_subgraph_vf2_mapping(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a different file for testing subgraph isomorphism functionality. Might be better to place this test there. https://github.com/Qiskit/retworkx/blob/main/tests/graph/test_subgraph_isomorphic.py
This commit fixes the construction of the reverse map when id_order=False. The previous versions of this did not correctly build the map in all cases. Co-authored-by: georgios-ts <[email protected]>
When playing with randomized ordering, I found this case where import retworkx
from retworkx import PyGraph, graph_vf2_mapping
G_nodes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350]
G_edges = [(732, 23), (23, 294), (294, 287), (287, 754), (754, 1086), (1086, 796), (796, 1333), (1333, 1139), (1139, 660), (660, 185), (185, 1191), (1191, 1240), (1240, 745), (745, 662), (662, 171), (171, 968), (968, 798), (798, 868), (868, 737), (737, 828), (828, 197), (197, 411), (411, 70), (70, 483), (483, 1077), (1077, 12), (12, 814), (814, 319), (319, 423), (423, 399), (399, 446), (446, 288), (288, 1196), (1196, 1233), (1233, 860), (860, 688), (688, 1097), (1097, 190), (190, 609), (609, 962), (962, 572), (572, 720), (720, 790), (790, 679), (679, 1275), (1275, 249), (249, 1237), (1237, 904), (904, 529), (529, 375), (863, 1231), (1231, 526), (526, 486), (486, 916), (916, 175), (175, 750), (750, 383), (383, 1165), (1165, 880), (880, 766), (766, 51), (51, 302), (302, 936), (936, 738), (738, 1110), (1110, 591), (591, 908), (908, 489), (489, 726), (726, 661), (661, 633), (633, 588), (588, 1101), (1101, 665), (665, 1017), (1017, 438), (438, 947), (947, 736), (736, 158), (158, 1262), (1262, 58), (58, 659), (659, 1268), (1268, 487), (487, 76), (76, 987), (987, 99), (99, 120), (120, 1172), (1172, 885), (885, 576), (576, 1304), (1304, 704), (704, 321), (321, 1341), (1341, 42), (42, 1149), (1149, 1055), (1055, 992), (992, 231), (231, 544), (344, 131), (131, 857), (857, 708), (708, 553), (553, 1022), (1022, 49), (49, 706), (706, 140), (140, 1286), (1286, 643), (643, 444), (444, 1164), (1164, 805), (805, 867), (867, 833), (833, 174), (174, 1019), (1019, 68), (68, 216), (216, 625), (625, 217), (217, 1346), (1346, 865), (865, 608), (608, 1045), (1045, 836), (836, 646), (646, 320), (320, 611), (611, 1211), (1211, 595), (595, 55), (55, 949), (949, 108), (108, 771), (771, 449), (449, 1343), (1343, 1057), (1057, 439), (439, 337), (337, 11), (11, 292), (292, 1138), (1138, 257), (257, 669), (669, 1248), (1248, 357), (357, 1006), (1006, 341), (341, 727), (727, 284), (192, 1287), (1287, 247), (247, 785), (785, 270), (270, 951), (951, 57), (57, 1293), (1293, 1309), (1309, 811), (811, 368), (368, 901), (901, 522), (522, 869), (869, 204), (204, 1269), (1269, 81), (81, 784), (784, 1318), (1318, 1313), (1313, 561), (561, 565), (565, 295), (295, 919), (919, 259), (259, 1072), (1072, 518), (518, 445), (445, 512), (512, 534), (534, 1126), (1126, 928), (928, 1224), (1224, 627), (627, 458), (458, 1184), (1184, 91), (91, 400), (400, 134), (134, 1147), (1147, 593), (593, 516), (516, 214), (214, 435), (435, 1141), (1141, 281), (281, 781), (781, 90), (90, 690), (690, 1334), (1334, 818), (818, 786), (1244, 648), (648, 886), (886, 763), (763, 821), (821, 1255), (1255, 920), (920, 414), (414, 658), (658, 350), (350, 740), (740, 899), (899, 19), (19, 897), (897, 883), (883, 523), (523, 707), (707, 1154), (1154, 779), (779, 278), (278, 1098), (1098, 501), (501, 1014), (1014, 964), (964, 1209), (1209, 129), (129, 1109), (1109, 1038), (1038, 1193), (1193, 35), (35, 870), (870, 460), (460, 1234), (1234, 1117), (1117, 953), (953, 409), (409, 467), (467, 1185), (1185, 685), (685, 809), (809, 132), (132, 16), (16, 844), (844, 954), (954, 480), (480, 590), (590, 803), (803, 799), (799, 980), (980, 1256), (1256, 272), (272, 275), (549, 985), (985, 929), (929, 815), (815, 279), (279, 364), (364, 984), (984, 506), (506, 1160), (1160, 1001), (1001, 628), (628, 304), (304, 568), (568, 993), (993, 1302), (1302, 139), (139, 663), (663, 881), (881, 907), (907, 1061), (1061, 1143), (1143, 892), (892, 787), (787, 277), (277, 729), (729, 1213), (1213, 702), (702, 347), (347, 1278), (1278, 1155), (1155, 957), (957, 422), (422, 474), (474, 756), (756, 852), (852, 780), (780, 201), (201, 567), (567, 606), (606, 744), (744, 1025), (1025, 109), (109, 743), (743, 845), (845, 50), (50, 1243), (1243, 336), (336, 678), (678, 60), (60, 1324), (1324, 1073), (1073, 1258), (1108, 24), (24, 419), (419, 1210), (1210, 450), (450, 1095), (1095, 37), (37, 282), (282, 156), (156, 1305), (1305, 122), (122, 176), (176, 246), (246, 472), (472, 463), (463, 931), (931, 1288), (1288, 1115), (1115, 882), (882, 783), (783, 96), (96, 177), (177, 714), (714, 527), (527, 476), (476, 753), (753, 453), (453, 371), (371, 1161), (1161, 14), (14, 778), (778, 1083), (1083, 233), (233, 274), (274, 1135), (1135, 163), (163, 515), (515, 938), (938, 52), (52, 461), (461, 173), (173, 1338), (1338, 1331), (1331, 359), (359, 524), (524, 1023), (1023, 311), (311, 765), (765, 1186), (1186, 219), (219, 32), (32, 71), (470, 1043), (1043, 148), (148, 465), (465, 179), (179, 1216), (1216, 1144), (1144, 557), (557, 468), (468, 136), (136, 172), (172, 757), (757, 1091), (1091, 834), (834, 1065), (1065, 504), (504, 232), (232, 297), (297, 220), (220, 1264), (1264, 280), (280, 755), (755, 820), (820, 948), (948, 1137), (1137, 913), (913, 972), (972, 234), (234, 210), (210, 180), (180, 728), (728, 1159), (1159, 1044), (1044, 1116), (1116, 1215), (1215, 313), (313, 887), (887, 550), (550, 412), (412, 713), (713, 1173), (1173, 326), (326, 699), (699, 1096), (1096, 994), (994, 618), (618, 1062), (1062, 1170), (1170, 119), (119, 17), (17, 198), (198, 673), (581, 601), (601, 547), (547, 902), (902, 982), (982, 551), (551, 112), (112, 1087), (1087, 428), (428, 251), (251, 1078), (1078, 218), (218, 768), (768, 404), (404, 1272), (1272, 496), (496, 1321), (1321, 106), (106, 66), (66, 1150), (1150, 539), (539, 1245), (1245, 511), (511, 229), (229, 75), (75, 604), (604, 475), (475, 774), (774, 876), (876, 1218), (1218, 1032), (1032, 960), (960, 169), (169, 366), (366, 725), (725, 970), (970, 53), (53, 97), (97, 1189), (1189, 806), (806, 1345), (1345, 540), (540, 842), (842, 372), (372, 1142), (1142, 1163), (1163, 1315), (1315, 1339), (1339, 138), (138, 1323), (1323, 317), (317, 683), (760, 184), (184, 680), (680, 933), (933, 804), (804, 1088), (1088, 379), (379, 1225), (1225, 554), (554, 443), (443, 1013), (1013, 854), (854, 269), (269, 918), (918, 5), (5, 498), (498, 543), (543, 241), (241, 181), (181, 13), (13, 110), (110, 318), (318, 1295), (1295, 26), (26, 586), (586, 634), (634, 1046), (1046, 153), (153, 227), (227, 1050), (1050, 1011), (1011, 333), (333, 252), (252, 162), (162, 256), (256, 355), (355, 250), (250, 1085), (1085, 597), (597, 1223), (1223, 521), (521, 1158), (1158, 640), (640, 545), (545, 623), (623, 142), (142, 479), (479, 410), (410, 1092), (1092, 560), (560, 677), (677, 1127), (1257, 602), (602, 1190), (1190, 657), (657, 1337), (1337, 413), (413, 420), (420, 1075), (1075, 215), (215, 137), (137, 289), (289, 840), (840, 424), (424, 69), (69, 835), (835, 1281), (1281, 945), (945, 584), (584, 1060), (1060, 830), (830, 1132), (1132, 789), (789, 87), (87, 1093), (1093, 290), (290, 362), (362, 748), (748, 104), (104, 613), (613, 405), (405, 950), (950, 943), (943, 1314), (1314, 990), (990, 1340), (1340, 1145), (1145, 123), (123, 22), (22, 1335), (1335, 921), (921, 556), (556, 1079), (1079, 944), (944, 94), (94, 832), (832, 434), (434, 705), (705, 558), (558, 308), (308, 958), (958, 890), (890, 1285), (1325, 580), (580, 866), (866, 1), (1, 955), (955, 603), (603, 494), (494, 88), (88, 473), (473, 797), (797, 620), (620, 535), (535, 900), (900, 668), (668, 1200), (1200, 178), (178, 442), (442, 1198), (1198, 973), (973, 1267), (1267, 1129), (1129, 157), (157, 571), (571, 114), (114, 1054), (1054, 111), (111, 189), (189, 1153), (1153, 782), (782, 675), (675, 741), (741, 208), (208, 1226), (1226, 328), (328, 1168), (1168, 983), (983, 1316), (1316, 1076), (1076, 59), (59, 541), (541, 1201), (1201, 742), (742, 1212), (1212, 711), (711, 363), (363, 305), (305, 712), (712, 605), (605, 670), (670, 426), (426, 1241), (1241, 1042), (719, 631), (631, 1204), (1204, 1292), (1292, 1199), (1199, 21), (21, 615), (615, 847), (847, 47), (47, 429), (429, 381), (381, 298), (298, 652), (652, 242), (242, 248), (248, 520), (520, 323), (323, 228), (228, 1298), (1298, 150), (150, 1105), (1105, 160), (160, 315), (315, 1265), (1265, 546), (546, 105), (105, 1348), (1348, 607), (607, 188), (188, 334), (334, 651), (651, 566), (566, 1003), (1003, 1219), (1219, 484), (484, 1004), (1004, 1021), (1021, 213), (213, 952), (952, 1222), (1222, 264), (264, 352), (352, 1294), (1294, 115), (115, 464), (464, 1048), (1048, 1030), (1030, 238), (238, 1029), (1029, 1152), (1152, 967), (967, 749), (7, 126), (126, 674), (674, 209), (209, 1134), (1134, 1015), (1015, 146), (146, 925), (925, 851), (851, 374), (374, 1276), (1276, 10), (10, 182), (182, 356), (356, 353), (353, 700), (700, 959), (959, 747), (747, 72), (72, 360), (360, 1181), (1181, 258), (258, 332), (332, 508), (508, 1102), (1102, 800), (800, 961), (961, 457), (457, 31), (31, 888), (888, 709), (709, 101), (101, 1125), (1125, 1058), (1058, 773), (773, 877), (877, 432), (432, 579), (579, 843), (843, 935), (935, 116), (116, 312), (312, 1124), (1124, 430), (430, 536), (536, 793), (793, 1100), (1100, 642), (642, 1122), (1122, 1036), (1036, 1151), (1151, 585), (582, 1051), (1051, 1177), (1177, 1296), (1296, 261), (261, 1230), (1230, 875), (875, 45), (45, 77), (77, 759), (759, 1059), (1059, 466), (466, 195), (195, 859), (859, 455), (455, 401), (401, 39), (39, 193), (193, 1035), (1035, 124), (124, 697), (697, 1329), (1329, 396), (396, 1039), (1039, 303), (303, 636), (636, 730), (730, 698), (698, 1063), (1063, 1299), (1299, 1018), (1018, 1099), (1099, 629), (629, 478), (478, 1242), (1242, 903), (903, 61), (61, 113), (113, 502), (502, 1167), (1167, 199), (199, 354), (354, 1236), (1236, 1081), (1081, 1009), (1009, 926), (926, 1169), (1169, 645), (645, 135), (135, 632), (632, 838), (838, 1229), (1344, 792), (792, 1246), (1246, 103), (103, 48), (48, 932), (932, 395), (395, 477), (477, 626), (626, 1320), (1320, 1247), (1247, 361), (361, 155), (155, 715), (715, 689), (689, 1069), (1069, 1176), (1176, 1188), (1188, 503), (503, 144), (144, 896), (896, 1020), (1020, 894), (894, 56), (56, 342), (342, 746), (746, 293), (293, 244), (244, 1119), (1119, 940), (940, 167), (167, 63), (63, 392), (392, 1133), (1133, 417), (417, 791), (791, 310), (310, 268), (268, 505), (505, 874), (874, 340), (340, 260), (260, 583), (583, 519), (519, 1005), (1005, 1290), (1290, 1206), (1206, 1113), (1113, 1027), (1027, 20), (20, 1016), (1016, 1227), (1037, 622), (622, 397), (397, 810), (810, 493), (493, 427), (427, 1026), (1026, 548), (548, 978), (978, 211), (211, 772), (772, 1007), (1007, 1283), (1283, 78), (78, 614), (614, 776), (776, 1118), (1118, 824), (824, 813), (813, 694), (694, 1217), (1217, 587), (587, 34), (34, 514), (514, 542), (542, 1297), (1297, 517), (517, 380), (380, 471), (471, 671), (671, 152), (152, 878), (878, 1252), (1252, 338), (338, 977), (977, 864), (864, 777), (777, 15), (15, 307), (307, 41), (41, 133), (133, 230), (230, 879), (879, 40), (40, 528), (528, 989), (989, 819), (819, 991), (991, 481), (481, 826), (826, 723), (723, 1140), (301, 1056), (1056, 388), (388, 862), (862, 1000), (1000, 802), (802, 1284), (1284, 263), (263, 923), (923, 537), (537, 36), (36, 329), (329, 837), (837, 325), (325, 764), (764, 722), (722, 348), (348, 9), (9, 224), (224, 624), (624, 1052), (1052, 946), (946, 895), (895, 1330), (1330, 650), (650, 910), (910, 510), (510, 853), (853, 330), (330, 909), (909, 971), (971, 507), (507, 1317), (1317, 898), (898, 969), (969, 696), (696, 653), (653, 415), (415, 1336), (1336, 1214), (1214, 1300), (1300, 610), (610, 934), (934, 154), (154, 846), (846, 559), (559, 370), (370, 1263), (1263, 469), (469, 988), (988, 107), (107, 149), (638, 221), (221, 1306), (1306, 43), (43, 656), (656, 212), (212, 262), (262, 407), (407, 1239), (1239, 121), (121, 1180), (1180, 693), (693, 770), (770, 462), (462, 538), (538, 924), (924, 1308), (1308, 718), (718, 873), (873, 884), (884, 841), (841, 65), (65, 117), (117, 1183), (1183, 196), (196, 441), (441, 998), (998, 1156), (1156, 599), (599, 1103), (1103, 225), (225, 377), (377, 85), (85, 433), (433, 1024), (1024, 695), (695, 1157), (1157, 598), (598, 807), (807, 500), (500, 942), (942, 459), (459, 296), (296, 1312), (1312, 569), (569, 403), (403, 100), (100, 8), (8, 394), (394, 62), (62, 226), (226, 767), (1327, 1064), (1064, 827), (827, 1261), (1261, 89), (89, 654), (654, 1028), (1028, 384), (384, 578), (578, 641), (641, 1104), (1104, 941), (941, 159), (159, 915), (915, 703), (703, 1049), (1049, 343), (343, 1053), (1053, 1071), (1071, 436), (436, 509), (509, 716), (716, 1171), (1171, 1034), (1034, 1270), (1270, 351), (351, 831), (831, 999), (999, 817), (817, 1349), (1349, 345), (345, 485), (485, 492), (492, 930), (930, 574), (574, 203), (203, 222), (222, 849), (849, 612), (612, 672), (672, 825), (825, 1089), (1089, 145), (145, 367), (367, 630), (630, 98), (98, 1130), (1130, 979), (979, 1249), (1249, 600), (600, 265), (265, 808), (739, 592), (592, 1260), (1260, 335), (335, 552), (552, 84), (84, 73), (73, 692), (692, 1307), (1307, 752), (752, 691), (691, 1301), (1301, 1228), (1228, 309), (309, 283), (283, 18), (18, 1282), (1282, 769), (769, 425), (425, 365), (365, 762), (762, 891), (891, 939), (939, 1111), (1111, 1070), (1070, 751), (751, 644), (644, 531), (531, 421), (421, 83), (83, 86), (86, 38), (38, 570), (570, 316), (316, 235), (235, 710), (710, 1066), (1066, 273), (273, 525), (525, 1205), (1205, 927), (927, 562), (562, 1274), (1274, 166), (166, 812), (812, 974), (974, 205), (205, 373), (373, 573), (573, 619), (619, 406), (406, 243), (390, 200), (200, 1082), (1082, 4), (4, 29), (29, 437), (437, 6), (6, 1319), (1319, 855), (855, 822), (822, 30), (30, 267), (267, 170), (170, 385), (385, 850), (850, 102), (102, 1182), (1182, 639), (639, 667), (667, 1012), (1012, 1303), (1303, 0), (0, 997), (997, 1080), (1080, 914), (914, 322), (322, 1347), (1347, 130), (130, 912), (912, 339), (339, 95), (95, 856), (856, 823), (823, 64), (64, 1136), (1136, 775), (775, 1291), (1291, 456), (456, 490), (490, 327), (327, 684), (684, 393), (393, 3), (3, 165), (165, 848), (848, 794), (794, 1328), (1328, 271), (271, 735), (735, 1273), (1273, 721), (721, 986), (491, 276), (276, 575), (575, 1195), (1195, 93), (93, 687), (687, 161), (161, 937), (937, 25), (25, 1148), (1148, 314), (314, 1174), (1174, 795), (795, 1238), (1238, 637), (637, 1041), (1041, 839), (839, 965), (965, 27), (27, 358), (358, 905), (905, 240), (240, 1332), (1332, 1084), (1084, 701), (701, 331), (331, 324), (324, 118), (118, 1277), (1277, 346), (346, 1166), (1166, 963), (963, 734), (734, 1192), (1192, 408), (408, 1208), (1208, 1220), (1220, 80), (80, 956), (956, 1031), (1031, 1197), (1197, 369), (369, 893), (893, 717), (717, 616), (616, 147), (147, 452), (452, 143), (143, 1259), (1259, 207), (207, 871), (871, 1114), (46, 125), (125, 431), (431, 981), (981, 253), (253, 378), (378, 398), (398, 44), (44, 74), (74, 237), (237, 758), (758, 1271), (1271, 1250), (1250, 245), (245, 1179), (1179, 386), (386, 254), (254, 54), (54, 1326), (1326, 1094), (1094, 1175), (1175, 92), (92, 448), (448, 299), (299, 1322), (1322, 1310), (1310, 872), (872, 1279), (1279, 349), (349, 761), (761, 451), (451, 239), (239, 555), (555, 33), (33, 497), (497, 389), (389, 686), (686, 1202), (1202, 996), (996, 236), (236, 664), (664, 168), (168, 731), (731, 1008), (1008, 922), (922, 563), (563, 1187), (1187, 858), (858, 1207), (1207, 440), (440, 482), (482, 1068), (564, 1074), (1074, 801), (801, 1107), (1107, 1289), (1289, 79), (79, 306), (306, 266), (266, 183), (183, 141), (141, 975), (975, 532), (532, 1254), (1254, 67), (67, 382), (382, 387), (387, 376), (376, 594), (594, 495), (495, 1178), (1178, 649), (649, 1350), (1350, 1221), (1221, 187), (187, 911), (911, 589), (589, 1203), (1203, 1120), (1120, 1235), (1235, 416), (416, 1106), (1106, 681), (681, 1121), (1121, 255), (255, 596), (596, 1128), (1128, 617), (617, 223), (223, 1002), (1002, 1040), (1040, 655), (655, 164), (164, 186), (186, 917), (917, 1112), (1112, 291), (291, 488), (488, 454), (454, 1162), (1162, 391), (391, 128), (128, 666), (499, 682), (682, 1010), (1010, 1253), (1253, 2), (2, 1280), (1280, 816), (816, 191), (191, 28), (28, 1123), (1123, 127), (127, 533), (533, 1067), (1067, 906), (906, 1342), (1342, 1131), (1131, 418), (418, 1311), (1311, 1251), (1251, 647), (647, 889), (889, 724), (724, 206), (206, 1146), (1146, 966), (966, 676), (676, 151), (151, 202), (202, 635), (635, 300), (300, 1232), (1232, 1090), (1090, 513), (513, 1266), (1266, 194), (194, 286), (286, 577), (577, 285), (285, 1033), (1033, 447), (447, 1194), (1194, 733), (733, 976), (976, 621), (621, 829), (829, 995), (995, 1047), (1047, 530), (530, 82), (82, 861), (861, 788), (732, 863), (294, 526), (754, 916), (796, 750), (1139, 1165), (185, 766), (1240, 302), (662, 738), (968, 591), (868, 489), (828, 661), (411, 588), (483, 665), (12, 438), (319, 736), (399, 1262), (288, 659), (1233, 487), (688, 987), (190, 120), (962, 885), (720, 1304), (679, 321), (249, 42), (904, 1055), (375, 231), (1231, 131), (486, 708), (175, 1022), (383, 706), (880, 1286), (51, 444), (936, 805), (1110, 833), (908, 1019), (726, 216), (633, 217), (1101, 865), (1017, 1045), (947, 646), (158, 611), (58, 595), (1268, 949), (76, 771), (99, 1343), (1172, 439), (576, 11), (704, 1138), (1341, 669), (1149, 357), (992, 341), (544, 284), (344, 192), (857, 247), (553, 270), (49, 57), (140, 1309), (643, 368), (1164, 522), (867, 204), (174, 81), (68, 1318), (625, 561), (1346, 295), (608, 259), (836, 518), (320, 512), (1211, 1126), (55, 1224), (108, 458), (449, 91), (1057, 134), (337, 593), (292, 214), (257, 1141), (1248, 781), (1006, 690), (727, 818), (1287, 648), (785, 763), (951, 1255), (1293, 414), (811, 350), (901, 899), (869, 897), (1269, 523), (784, 1154), (1313, 278), (565, 501), (919, 964), (1072, 129), (445, 1038), (534, 35), (928, 460), (627, 1117), (1184, 409), (400, 1185), (1147, 809), (516, 16), (435, 954), (281, 590), (90, 799), (1334, 1256), (786, 275), (1244, 549), (886, 929), (821, 279), (920, 984), (658, 1160), (740, 628), (19, 568), (883, 1302), (707, 663), (779, 907), (1098, 1143), (1014, 787), (1209, 729), (1109, 702), (1193, 1278), (870, 957), (1234, 474), (953, 852), (467, 201), (685, 606), (132, 1025), (844, 743), (480, 50), (803, 336), (980, 60), (272, 1073), (985, 24), (815, 1210), (364, 1095), (506, 282), (1001, 1305), (304, 176), (993, 472), (139, 931), (881, 1115), (1061, 783), (892, 177), (277, 527), (1213, 753), (347, 371), (1155, 14), (422, 1083), (756, 274), (780, 163), (567, 938), (744, 461), (109, 1338), (845, 359), (1243, 1023), (678, 765), (1324, 219), (1258, 71), (1108, 470), (419, 148), (450, 179), (37, 1144), (156, 468), (122, 172), (246, 1091), (463, 1065), (1288, 232), (882, 220), (96, 280), (714, 820), (476, 1137), (453, 972), (1161, 210), (778, 728), (233, 1044), (1135, 1215), (515, 887), (52, 412), (173, 1173), (1331, 699), (524, 994), (311, 1062), (1186, 119), (32, 198), (1043, 601), (465, 902), (1216, 551), (557, 1087), (136, 251), (757, 218), (834, 404), (504, 496), (297, 106), (1264, 1150), (755, 1245), (948, 229), (913, 604), (234, 774), (180, 1218), (1159, 960), (1116, 366), (313, 970), (550, 97), (713, 806), (326, 540), (1096, 372), (618, 1163), (1170, 1339), (17, 1323), (673, 683), (581, 760), (547, 680), (982, 804), (112, 379), (428, 554), (1078, 1013), (768, 269), (1272, 5), (1321, 543), (66, 181), (539, 110), (511, 1295), (75, 586), (475, 1046), (876, 227), (1032, 1011), (169, 252), (725, 256), (53, 250), (1189, 597), (1345, 521), (842, 640), (1142, 623), (1315, 479), (138, 1092), (317, 677), (184, 602), (933, 657), (1088, 413), (1225, 1075), (443, 137), (854, 840), (918, 69), (498, 1281), (241, 584), (13, 830), (318, 789), (26, 1093), (634, 362), (153, 104), (1050, 405), (333, 943), (162, 990), (355, 1145), (1085, 22), (1223, 921), (1158, 1079), (545, 94), (142, 434), (410, 558), (560, 958), (1127, 1285), (1257, 1325), (1190, 866), (1337, 955), (420, 494), (215, 473), (289, 620), (424, 900), (835, 1200), (945, 442), (1060, 973), (1132, 1129), (87, 571), (290, 1054), (748, 189), (613, 782), (950, 741), (1314, 1226), (1340, 1168), (123, 1316), (1335, 59), (556, 1201), (944, 1212), (832, 363), (705, 712), (308, 670), (890, 1241), (580, 631), (1, 1292), (603, 21), (88, 847), (797, 429), (535, 298), (668, 242), (178, 520), (1198, 228), (1267, 150), (157, 160), (114, 1265), (111, 105), (1153, 607), (675, 334), (208, 566), (328, 1219), (983, 1004), (1076, 213), (541, 1222), (742, 352), (711, 115), (305, 1048), (605, 238), (426, 1152), (1042, 749), (719, 7), (1204, 674), (1199, 1134), (615, 146), (47, 851), (381, 1276), (652, 182), (248, 353), (323, 959), (1298, 72), (1105, 1181), (315, 332), (546, 1102), (1348, 961), (188, 31), (651, 709), (1003, 1125), (484, 773), (1021, 432), (952, 843), (264, 116), (1294, 1124), (464, 536), (1030, 1100), (1029, 1122), (967, 1151), (126, 1051), (209, 1296), (1015, 1230), (925, 45), (374, 759), (10, 466), (356, 859), (700, 401), (747, 193), (360, 124), (258, 1329), (508, 1039), (800, 636), (457, 698), (888, 1299), (101, 1099), (1058, 478), (877, 903), (579, 113), (935, 1167), (312, 354), (430, 1081), (793, 926), (642, 645), (1036, 632), (585, 1229), (582, 1344), (1177, 1246), (261, 48), (875, 395), (77, 626), (1059, 1247), (195, 155), (455, 689), (39, 1176), (1035, 503), (697, 896), (396, 894), (303, 342), (730, 293), (1063, 1119), (1018, 167), (629, 392), (1242, 417), (61, 310), (502, 505), (199, 340), (1236, 583), (1009, 1005), (1169, 1206), (135, 1027), (838, 1016), (792, 622), (103, 810), (932, 427), (477, 548), (1320, 211), (361, 1007), (715, 78), (1069, 776), (1188, 824), (144, 694), (1020, 587), (56, 514), (746, 1297), (244, 380), (940, 671), (63, 878), (1133, 338), (791, 864), (268, 15), (874, 41), (260, 230), (519, 40), (1290, 989), (1113, 991), (20, 826), (1227, 1140), (1037, 301), (397, 388), (493, 1000), (1026, 1284), (978, 923), (772, 36), (1283, 837), (614, 764), (1118, 348), (813, 224), (1217, 1052), (34, 895), (542, 650), (517, 510), (471, 330), (152, 971), (1252, 1317), (977, 969), (777, 653), (307, 1336), (133, 1300), (879, 934), (528, 846), (819, 370), (481, 469), (723, 107), (1056, 221), (862, 43), (802, 212), (263, 407), (537, 121), (329, 693), (325, 462), (722, 924), (9, 718), (624, 884), (946, 65), (1330, 1183), (910, 441), (853, 1156), (909, 1103), (507, 377), (898, 433), (696, 695), (415, 598), (1214, 500), (610, 459), (154, 1312), (559, 403), (1263, 8), (988, 62), (149, 767), (638, 1327), (1306, 827), (656, 89), (262, 1028), (1239, 578), (1180, 1104), (770, 159), (538, 703), (1308, 343), (873, 1071), (841, 509), (117, 1171), (196, 1270), (998, 831), (599, 817), (225, 345), (85, 492), (1024, 574), (1157, 222), (807, 612), (942, 825), (296, 145), (569, 630), (100, 1130), (394, 1249), (226, 265), (1064, 592), (1261, 335), (654, 84), (384, 692), (641, 752), (941, 1301), (915, 309), (1049, 18), (1053, 769), (436, 365), (716, 891), (1034, 1111), (351, 751), (999, 531), (1349, 83), (485, 38), (930, 316), (203, 710), (849, 273), (672, 1205), (1089, 562), (367, 166), (98, 974), (979, 373), (600, 619), (808, 243), (739, 390), (1260, 1082), (552, 29), (73, 6), (1307, 855), (691, 30), (1228, 170), (283, 850), (1282, 1182), (425, 667), (762, 1303), (939, 997), (1070, 914), (644, 1347), (421, 912), (86, 95), (570, 823), (235, 1136), (1066, 1291), (525, 490), (927, 684), (1274, 3), (812, 848), (205, 1328), (573, 735), (406, 721), (200, 276), (4, 1195), (437, 687), (1319, 937), (822, 1148), (267, 1174), (385, 1238), (102, 1041), (639, 965), (1012, 358), (0, 240), (1080, 1084), (322, 331), (130, 118), (339, 346), (856, 963), (64, 1192), (775, 1208), (456, 80), (327, 1031), (393, 369), (165, 717), (794, 147), (271, 143), (1273, 207), (986, 1114), (491, 46), (575, 431), (93, 253), (161, 398), (25, 74), (314, 758), (795, 1250), (637, 1179), (839, 254), (27, 1326), (905, 1175), (1332, 448), (701, 1322), (324, 872), (1277, 349), (1166, 451), (734, 555), (408, 497), (1220, 686), (956, 996), (1197, 664), (893, 731), (616, 922), (452, 1187), (1259, 1207), (871, 482), (125, 1074), (981, 1107), (378, 79), (44, 266), (237, 141), (1271, 532), (245, 67), (386, 387), (54, 594), (1094, 1178), (92, 1350), (299, 187), (1310, 589), (1279, 1120), (761, 416), (239, 681), (33, 255), (389, 1128), (1202, 223), (236, 1040), (168, 164), (1008, 917), (563, 291), (858, 454), (440, 391), (1068, 666), (564, 499), (801, 1010), (1289, 2), (306, 816), (183, 28), (975, 127), (1254, 1067), (382, 1342), (376, 418), (495, 1251), (649, 889), (1221, 206), (911, 966), (1203, 151), (1235, 635), (1106, 1232), (1121, 513), (596, 194), (617, 577), (1002, 1033), (655, 1194), (186, 976), (1112, 829), (488, 1047), (1162, 82), (128, 788)]
G = PyGraph()
G.add_nodes_from(G_nodes)
G.add_edges_from_no_data(G_edges)
H = retworkx.generators.hexagonal_lattice_graph(20, 20)
mapping = graph_vf2_mapping(G, H, subgraph=True, id_order=True)
print(mapping) |
@1ucian0 If you pass |
I see some optinos:
|
In principle, yes. But since we can't really return a generator from Rust (see #71) (i.e something that lazily evaluates the results) we have to compute all possible mappings. This might be prohibited for large graphs in terms of performance.
Yes
It should not have any effect. |
Let's go that way in that case, so |
Ok, after #375 the result should be deterministic. |
Superseded by #376 |
Building on top of #368, this PR refactors Vf2 algorithm and implements a vf2_mapping function that returns a custom python class that acts as a python iterator that lazily evaluates all valid Vf2 mappings. The "trick" that allows the lazily evaluation is to take ownership of a copy of the graphs. We can do this (with minimal overhead) since we were already creating new graphs in case of id_order=False or nodes_removed=True. At the same time, it adjusts Vf2ppSorter to handle graphs with non-contiguous node ids. Co-authored-by: Matthew Treinish <[email protected]> * Add vf2 mapping functions This commit adds a new function vf2_mapping which is used to get the isomorphic node mapping between 2 graphs. It works in the same way as is_isomorphic() but instead of simply returning a boolean whether the graphs are isomorphic it returns the node id mapping from first to second for the matching. * Fix reverse mapping construction with vf2pp mapping This commit fixes the construction of the reverse map when id_order=False. The previous versions of this did not correctly build the map in all cases. Co-authored-by: georgios-ts <[email protected]> * Add vf2pp remapping failure test case * Don't remap indices if no match found * Fix clippy failures * Use NodeMap for return type * Run cargo fmt * return an iterator over all valid vf2 mappings * update release note * lint * fix Vf2ppSorter to use node id instead of edge insertion order as a tie breaker * fix clippy warning * update text signature * update tests since now we can deterministically predict the output mapping * add call_limit kwarg in Vf2 algorithm * run cargo fmt * lint * resolve all conflicts * update release note and add more tests * call_limit does not need to be explicitly set to None Co-authored-by: Matthew Treinish <[email protected]> * simplify iteration in gc protocol Co-authored-by: Matthew Treinish <[email protected]> * update vf2 doc Co-authored-by: Matthew Treinish <[email protected]> * cargo fmt + remove unnecessary mut ref in semantic matcher * more tests * fix clippy error * fix failing test case * Fix docstring typo Co-authored-by: Matthew Treinish <[email protected]>
This commit adds a new function vf2_mapping which is used to get the
isomorphic node mapping between 2 graphs. It works in the same way as
is_isomorphic() but instead of simply returning a boolean whether the
graphs are isomorphic it returns the node id mapping from first to
second for the matching.
TODO:
NodeMap
return type being introduced in Add substitute_node_with_subgraph method to PyDiGraph #312 instead of returning a dict