cpp-pd-code-simplify-interface 0.1.17__tar.gz → 0.1.19__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 (12) hide show
  1. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/PKG-INFO +3 -2
  2. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/README.md +2 -1
  3. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp +40 -58
  4. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/pyproject.toml +1 -1
  5. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/build_backend/cpp_pd_code_simplify_interface_build_backend.py +0 -0
  6. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/__init__.py +0 -0
  7. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/__main__.py +0 -0
  8. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/_worker.py +0 -0
  9. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp +0 -0
  10. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/data/src/native_interface.cpp +0 -0
  11. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/main.py +0 -0
  12. {cpp_pd_code_simplify_interface-0.1.17 → cpp_pd_code_simplify_interface-0.1.19}/cpp_pd_code_simplify_interface/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpp-pd-code-simplify-interface
3
- Version: 0.1.17
3
+ Version: 0.1.19
4
4
  Summary: Python interface for cpp-pd-code-simplify with runtime C++ compilation.
5
5
  License-Expression: MIT
6
6
  Author: GGN_2015
@@ -79,7 +79,8 @@ the C++ backend for that phase. The backend call runs in a helper process, so
79
79
  `Ctrl+C` can terminate active C++ work and its worker threads cleanly.
80
80
  Use `show_step_pd=True`, or CLI flag `--show-step-pd`, to print
81
81
  `step_pd_code[ROUND]: PD[...]` to stdout after each mid-simplification witness
82
- is applied and before that round's automatic R1/nugatory cleanup.
82
+ is applied and canonicalized, before that round's automatic R1/nugatory
83
+ cleanup.
83
84
 
84
85
  Batch use:
85
86
 
@@ -59,7 +59,8 @@ the C++ backend for that phase. The backend call runs in a helper process, so
59
59
  `Ctrl+C` can terminate active C++ work and its worker threads cleanly.
60
60
  Use `show_step_pd=True`, or CLI flag `--show-step-pd`, to print
61
61
  `step_pd_code[ROUND]: PD[...]` to stdout after each mid-simplification witness
62
- is applied and before that round's automatic R1/nugatory cleanup.
62
+ is applied and canonicalized, before that round's automatic R1/nugatory
63
+ cleanup.
63
64
 
64
65
  Batch use:
65
66
 
@@ -68,6 +68,8 @@ struct CrossingState {
68
68
 
69
69
  using LabelMap = std::unordered_map<int, std::vector<Endpoint>>;
70
70
 
71
+ PDCode canonical_output_code(const PDCode& code);
72
+
71
73
  LabelMap build_label_map(const PDCode& code) {
72
74
  LabelMap labels;
73
75
  for (int c = 0; c < static_cast<int>(code.size()); ++c) {
@@ -227,6 +229,7 @@ PDCode erase_r1_moves(PDCode code, std::size_t& crossingless_components, int& mo
227
229
  }
228
230
 
229
231
  crossingless_components = after_removal.crossingless_components;
232
+ code = canonical_output_code(code);
230
233
  ++moves;
231
234
  changed = true;
232
235
  break;
@@ -237,7 +240,7 @@ PDCode erase_r1_moves(PDCode code, std::size_t& crossingless_components, int& mo
237
240
  }
238
241
  }
239
242
 
240
- return renumber_r1_order(code);
243
+ return canonical_output_code(renumber_r1_order(code));
241
244
  }
242
245
 
243
246
  std::map<int, std::set<int>> base_pd_graph(const PDCode& code) {
@@ -457,7 +460,7 @@ PDCode erase_one_nugatory_crossing(
457
460
  code = replace_arc_value(code, dx, bx);
458
461
  crossingless_components = after_removal.crossingless_components;
459
462
  ++moves;
460
- return renumber_full_dfs(code);
463
+ return canonical_output_code(renumber_full_dfs(code));
461
464
  }
462
465
 
463
466
  std::vector<std::vector<int>> raw_faces_from_pd_code(const PDCode& code) {
@@ -1320,7 +1323,9 @@ bool do_check(
1320
1323
  const std::vector<Endpoint>& red_path,
1321
1324
  const std::vector<int>& green_path,
1322
1325
  Direction direction,
1323
- SimplificationResult& result) {
1326
+ SimplificationResult& result,
1327
+ const SimplifierOptions& options) {
1328
+ check_timeout(options);
1324
1329
  std::vector<int> green_left_cross;
1325
1330
  green_left_cross.reserve(green_path.size());
1326
1331
 
@@ -1375,14 +1380,24 @@ bool do_check(
1375
1380
 
1376
1381
  bool good_path = true;
1377
1382
  while (!to_check.empty() && good_path) {
1383
+ check_timeout(options);
1378
1384
  const int start_key = to_check.back();
1379
1385
  to_check.pop_back();
1380
1386
  queued.erase(start_key);
1381
1387
  Endpoint cross_strand = endpoint_from_key(start_key);
1388
+ std::unordered_set<long long> trace_seen;
1382
1389
 
1383
1390
  while (true) {
1391
+ check_timeout(options);
1384
1392
  const int cross_key = endpoint_key(cross_strand);
1385
1393
  const Level current_level = check_result.at(cross_key);
1394
+ const long long trace_key =
1395
+ (static_cast<long long>(cross_key) << 1) ^
1396
+ static_cast<int>(current_level);
1397
+ if (!trace_seen.insert(trace_key).second) {
1398
+ good_path = false;
1399
+ break;
1400
+ }
1386
1401
  const Endpoint opposite = diagram.opposite(cross_strand);
1387
1402
  const int opposite_key = endpoint_key(opposite);
1388
1403
  const auto opposite_result = check_result.find(opposite_key);
@@ -1842,14 +1857,6 @@ void emit_step_pd(const SimplifierOptions& options, int round, const PDCode& cod
1842
1857
  }
1843
1858
  }
1844
1859
 
1845
- std::string no_path_restart_signature(
1846
- const PDCode& code,
1847
- std::size_t crossingless_components) {
1848
- std::ostringstream out;
1849
- out << crossingless_components << ':' << format_final_pd_code(code);
1850
- return out.str();
1851
- }
1852
-
1853
1860
  PDCode canonical_output_code(const PDCode& code) {
1854
1861
  return parse_pd_code(format_final_pd_code(code));
1855
1862
  }
@@ -2199,7 +2206,7 @@ PDSimplificationResult simplify_pd_code(
2199
2206
  const PDCode& code,
2200
2207
  std::size_t known_crossingless_components) {
2201
2208
  PDSimplificationResult result;
2202
- result.code = code;
2209
+ result.code = canonical_output_code(code);
2203
2210
  result.crossingless_components = known_crossingless_components;
2204
2211
 
2205
2212
  result.code = erase_r1_moves(
@@ -2350,7 +2357,14 @@ RedPathSearchOutcome search_single_red_path(
2350
2357
  if (green_path.size() >= red_path.size()) {
2351
2358
  continue;
2352
2359
  }
2353
- if (do_check(diagram, graph, red_path, green_path, Direction::Left, outcome.witness)) {
2360
+ if (do_check(
2361
+ diagram,
2362
+ graph,
2363
+ red_path,
2364
+ green_path,
2365
+ Direction::Left,
2366
+ outcome.witness,
2367
+ options)) {
2354
2368
  if (!options.require_applicable || witness_has_applicable_surgery(code, outcome.witness)) {
2355
2369
  outcome.found = true;
2356
2370
  outcome.completed = true;
@@ -2359,7 +2373,14 @@ RedPathSearchOutcome search_single_red_path(
2359
2373
  }
2360
2374
  clear_witness(outcome.witness);
2361
2375
  }
2362
- if (do_check(diagram, graph, red_path, green_path, Direction::Right, outcome.witness)) {
2376
+ if (do_check(
2377
+ diagram,
2378
+ graph,
2379
+ red_path,
2380
+ green_path,
2381
+ Direction::Right,
2382
+ outcome.witness,
2383
+ options)) {
2363
2384
  if (!options.require_applicable || witness_has_applicable_surgery(code, outcome.witness)) {
2364
2385
  outcome.found = true;
2365
2386
  outcome.completed = true;
@@ -2550,7 +2571,6 @@ ReductionResult reduce_pd_code(
2550
2571
  ReductionResult output;
2551
2572
  output.code = code;
2552
2573
  output.crossingless_components = known_crossingless_components;
2553
- std::set<std::string> exhausted_no_path_signatures;
2554
2574
 
2555
2575
  try {
2556
2576
  check_timeout(run_options);
@@ -2568,7 +2588,7 @@ ReductionResult reduce_pd_code(
2568
2588
 
2569
2589
  const PDSimplificationResult prepared =
2570
2590
  simplify_pd_code(code, known_crossingless_components);
2571
- output.code = prepared.code;
2591
+ output.code = canonical_output_code(prepared.code);
2572
2592
  output.crossingless_components = prepared.crossingless_components;
2573
2593
  output.reidemeister_i_moves = prepared.reidemeister_i_moves;
2574
2594
  output.nugatory_crossing_moves = prepared.nugatory_crossing_moves;
@@ -2643,45 +2663,6 @@ ReductionResult reduce_pd_code(
2643
2663
  }
2644
2664
 
2645
2665
  if (!search.found) {
2646
- if (run_options.max_paths == -1) {
2647
- check_timeout(run_options);
2648
- const std::string signature = no_path_restart_signature(
2649
- output.code, output.crossingless_components);
2650
- if (exhausted_no_path_signatures.insert(signature).second) {
2651
- const std::size_t before_restart_crossings = output.code.size();
2652
- const std::size_t before_restart_crossingless =
2653
- output.crossingless_components;
2654
- const PDSimplificationResult restarted =
2655
- simplify_pd_code(
2656
- canonical_output_code(output.code),
2657
- output.crossingless_components);
2658
- const bool changed =
2659
- restarted.code != output.code ||
2660
- restarted.crossingless_components != output.crossingless_components;
2661
- output.code = restarted.code;
2662
- output.crossingless_components = restarted.crossingless_components;
2663
- output.reidemeister_i_moves += restarted.reidemeister_i_moves;
2664
- output.nugatory_crossing_moves += restarted.nugatory_crossing_moves;
2665
- {
2666
- std::ostringstream message;
2667
- message << "round " << round
2668
- << " canonical_restart changed="
2669
- << (changed ? "yes" : "no")
2670
- << " crossings=" << before_restart_crossings
2671
- << " -> " << output.code.size()
2672
- << " crossingless_components="
2673
- << before_restart_crossingless
2674
- << " -> " << output.crossingless_components
2675
- << " r1_moves=" << restarted.reidemeister_i_moves
2676
- << " nugatory_moves="
2677
- << restarted.nugatory_crossing_moves;
2678
- emit_progress(run_options, message.str());
2679
- }
2680
- if (changed) {
2681
- continue;
2682
- }
2683
- }
2684
- }
2685
2666
  {
2686
2667
  std::ostringstream message;
2687
2668
  message << "round " << round
@@ -2695,14 +2676,15 @@ ReductionResult reduce_pd_code(
2695
2676
  check_timeout(run_options);
2696
2677
  const MidSimplificationApplyResult applied =
2697
2678
  apply_simplification_witness(output.code, search, output.crossingless_components);
2679
+ const PDCode applied_code = canonical_output_code(applied.code);
2698
2680
  ++output.mid_simplification_rounds;
2699
- emit_step_pd(run_options, round, applied.code);
2700
- output.code = applied.code;
2681
+ emit_step_pd(run_options, round, applied_code);
2682
+ output.code = applied_code;
2701
2683
  output.crossingless_components = applied.crossingless_components;
2702
2684
  check_timeout(run_options);
2703
2685
  const PDSimplificationResult simplified =
2704
2686
  simplify_pd_code(output.code, output.crossingless_components);
2705
- output.code = simplified.code;
2687
+ output.code = canonical_output_code(simplified.code);
2706
2688
  output.crossingless_components = simplified.crossingless_components;
2707
2689
  output.reidemeister_i_moves += simplified.reidemeister_i_moves;
2708
2690
  output.nugatory_crossing_moves += simplified.nugatory_crossing_moves;
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cpp-pd-code-simplify-interface"
3
- version = "0.1.17"
3
+ version = "0.1.19"
4
4
  description = "Python interface for cpp-pd-code-simplify with runtime C++ compilation."
5
5
  authors = [
6
6
  {name = "GGN_2015", email = "neko@jlulug.org"}