Skip to content

Commit 0dfe93b

Browse files
authored
Merge pull request #1212 from CodingThrust/fix/simultaneous-incongruences-complexity
Fix SimultaneousIncongruences complexity to include the search period
2 parents 7c1ea4c + 2fc8669 commit 0dfe93b

184 files changed

Lines changed: 6915 additions & 1129 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/paper/reductions.typ‎

Lines changed: 557 additions & 49 deletions
Large diffs are not rendered by default.

‎docs/paper/references.bib‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,3 +2332,14 @@ @article{axler2019
23322332
year = {2019},
23332333
url = {https://www.maths.tcd.ie/EMIS/journals/JIS/VOL22/Axler/axler17.pdf}
23342334
}
2335+
2336+
@article{een2006,
2337+
author = {Niklas E{\'e}n and Niklas S{\"o}rensson},
2338+
title = {Translating Pseudo-Boolean Constraints into {SAT}},
2339+
journal = {Journal on Satisfiability, Boolean Modeling and Computation},
2340+
year = {2006},
2341+
volume = {2},
2342+
number = {1--4},
2343+
pages = {1--26},
2344+
doi = {10.3233/SAT190014},
2345+
}

‎docs/website/src/styles/details.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.typst-detail h3 { margin: 24px 0 10px; font-size: 17px; font-weight: 600; }
44
.typst-detail p { margin: 10px 0; }
55
.typst-detail svg { max-width: 100%; filter: invert(.9); }
6+
/* Direct glyph colors avoid WebKit rasterizing small filtered math into blocks. */
7+
.typst-detail .typst-math > svg { filter: none; }
8+
.typst-detail .typst-math [fill="#000000"] { fill: var(--ink); }
9+
.typst-detail .typst-math [stroke="#000000"] { stroke: var(--ink); }
610
.typst-math > svg { display: inline-block !important; vertical-align: baseline; }
711
div.typst-math { overflow-x: auto; margin: 14px 0; }
812
.typst-detail figure { margin: 20px 0; }

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎problemreductions-cli/src/cli.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,17 @@ mod tests {
507507
let cli = Cli::try_parse_from([
508508
"pred",
509509
"create",
510-
"3SAT",
510+
"2SAT",
511511
"--num-vars",
512512
"3",
513513
"--clauses",
514-
"1,2,3",
514+
"1,2",
515515
])
516516
.expect("variant alias parses");
517517
let Commands::Create(args) = cli.command else {
518518
panic!("expected create command");
519519
};
520-
assert_eq!(args.problem.as_deref(), Some("KSatisfiability/K3"));
520+
assert_eq!(args.problem.as_deref(), Some("KSatisfiability/K2"));
521521
assert_eq!(args.raw("num-vars"), Some("3"));
522522
}
523523

‎problemreductions-cli/src/commands/create/tests.rs‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ fn test_create_path_constrained_network_flow_rejects_invalid_paths() {
747747
}
748748

749749
#[test]
750-
fn test_create_staff_scheduling_reports_invalid_schedule_without_panic() {
750+
fn test_create_staff_scheduling_rejects_ragged_schedule() {
751751
let cli = Cli::try_parse_from([
752752
"pred",
753753
"create",
@@ -775,13 +775,7 @@ fn test_create_staff_scheduling_reports_invalid_schedule_without_panic() {
775775
auto_json: false,
776776
};
777777

778-
let result = std::panic::catch_unwind(|| create(&args, &out));
779-
assert!(result.is_ok(), "create should return an error, not panic");
780-
let err = result.unwrap().unwrap_err().to_string();
781-
assert!(
782-
err.contains("All rows") || err.contains("schedule 1 has 6 periods, expected 7"),
783-
"expected row-length validation error, got: {err}"
784-
);
778+
assert!(create(&args, &out).is_err());
785779
}
786780

787781
#[test]
@@ -954,7 +948,7 @@ fn test_create_timetable_design_outputs_problem_json() {
954948
}
955949

956950
#[test]
957-
fn test_create_timetable_design_reports_invalid_matrix_without_panic() {
951+
fn test_create_timetable_design_rejects_invalid_matrix() {
958952
let cli = Cli::try_parse_from([
959953
"pred",
960954
"create",
@@ -986,13 +980,7 @@ fn test_create_timetable_design_reports_invalid_matrix_without_panic() {
986980
auto_json: false,
987981
};
988982

989-
let result = std::panic::catch_unwind(|| create(&args, &out));
990-
assert!(result.is_ok(), "create should return an error, not panic");
991-
let err = result.unwrap().unwrap_err().to_string();
992-
assert!(
993-
err.contains("--craftsman-avail"),
994-
"expected timetable matrix validation error, got: {err}"
995-
);
983+
assert!(create(&args, &out).is_err());
996984
}
997985

998986
#[test]

‎problemreductions-cli/tests/cli_tests.rs‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn path_text_preserves_variant_conversion_steps() {
5151

5252
#[test]
5353
fn polynomial_comparison_default_layout_and_opt_in_proofs() {
54-
let args = ["path", "MIS", "QUBO", "--compare", "--limit", "3"];
54+
// The first two clique routes are equivalent; set-packing and feedback-arc routes add comparisons.
55+
let args = ["path", "MIS", "QUBO", "--compare", "--limit", "4"];
5556
let output = pred().args(args).output().unwrap();
5657
assert!(output.status.success());
5758
let text = String::from_utf8(output.stdout).unwrap();
@@ -63,14 +64,14 @@ fn polynomial_comparison_default_layout_and_opt_in_proofs() {
6364
assert!(text.contains("Path 1") && text.contains("num_vars"));
6465
assert!(!text.contains("[upper bound]") && !text.contains("[exact]"));
6566
assert!(text[pairs..unresolved]
66-
.contains("0 dominated, 1 equivalent, 2 proven incomparable, 0 unresolved"));
67+
.contains("2 dominated, 1 equivalent, 3 proven incomparable, 0 unresolved"));
6768
assert!(!text.contains("worst case:") && !text.contains("Generic candidate front"));
68-
assert!(text.contains("Paths 1, 2: proven incomparable"));
69-
assert!(text.contains("Paths 2, 3: Path 2 ≡ Path 3"));
69+
assert!(text.contains("Paths 1, 3: proven incomparable"));
70+
assert!(text.contains("Paths 1, 2: Path 1 ≡ Path 2"));
7071
assert!(
7172
text.contains("Ignores exact-cancellation families") && text.contains("bounded strata")
7273
);
73-
assert!(text.contains("2 proven incomparable, 0 unresolved"));
74+
assert!(text.contains("3 proven incomparable, 0 unresolved"));
7475
assert!(
7576
!text.contains("Field proofs") && !text.contains("Witness {") && !text.contains("f/g → ∞")
7677
);
@@ -79,8 +80,8 @@ fn polynomial_comparison_default_layout_and_opt_in_proofs() {
7980
assert!(output.status.success());
8081
let text = String::from_utf8(output.stdout).unwrap();
8182
assert!(
82-
text.contains("Paths 1, 2: proven incomparable")
83-
&& text.contains("Paths 2, 3: Path 2 ≡ Path 3")
83+
text.contains("Paths 1, 3: proven incomparable")
84+
&& text.contains("Paths 1, 2: Path 1 ≡ Path 2")
8485
);
8586
assert!(text.contains("Field proofs") && text.contains("f/g → ∞"));
8687
assert!(text.contains("f ≡ g after expansion"));
@@ -89,17 +90,25 @@ fn polynomial_comparison_default_layout_and_opt_in_proofs() {
8990
let output = pred().args(args).arg("--json").output().unwrap();
9091
assert!(output.status.success());
9192
let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
93+
for (route, step, name) in [
94+
(0, 0, "MaximumClique"),
95+
(1, 1, "MaximumClique"),
96+
(2, 1, "MaximumSetPacking"),
97+
(3, 2, "MinimumFeedbackArcSet"),
98+
] {
99+
assert_eq!(json["paths"][route]["path"][step]["to"]["name"], name);
100+
}
92101
let view = &json["polynomial_comparison"];
93102
assert_eq!(view["schema_version"], 5);
94103
assert_eq!(view["mode"], "generic");
95-
assert_eq!(view["counts"]["Incomparable"], 2);
104+
assert_eq!(view["counts"]["Incomparable"], 3);
96105
assert!(view.get("generic_counts").is_none());
97106
assert!(view.get("generic_candidate_front").is_none());
98107
assert!(view["pairs"][0]["fields"]["num_vars"]["forward"]["certificate"].is_object());
99-
let identity = &view["pairs"][2]["fields"]["num_vars"]["forward"]["certificate"];
108+
let identity = &view["pairs"][0]["fields"]["num_vars"]["forward"]["certificate"];
100109
assert_eq!(identity["kind"], "identity");
101110
assert_eq!(identity.as_object().unwrap().len(), 1);
102-
assert!(view["pairs"][2]["fields"]["num_vars"]
111+
assert!(view["pairs"][0]["fields"]["num_vars"]
103112
.get("generic")
104113
.is_none());
105114
let output = pred()

‎problemreductions-macros/src/lib.rs‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,38 +1328,6 @@ mod tests {
13281328
assert_eq!(error.to_string(), "duplicate `create` clause");
13291329
}
13301330

1331-
#[test]
1332-
fn declare_variants_generates_model_dispatch_without_solver_dispatch() {
1333-
let input: DeclareVariantsInput = syn::parse_quote! {
1334-
default Foo => "1",
1335-
};
1336-
let tokens = generate_declare_variants(&input).unwrap().to_string();
1337-
assert!(tokens.contains("factory :"), "expected factory field");
1338-
assert!(
1339-
tokens.contains("serialize_fn :"),
1340-
"expected serialize_fn field"
1341-
);
1342-
assert!(!tokens.contains("solve_typed_fn :"));
1343-
assert!(!tokens.contains("solve_fn :"));
1344-
assert!(
1345-
!tokens.contains("factory : None"),
1346-
"factory should not be None"
1347-
);
1348-
assert!(
1349-
!tokens.contains("serialize_fn : None"),
1350-
"serialize_fn should not be None"
1351-
);
1352-
assert!(!tokens.contains("find_cartesian"));
1353-
assert!(
1354-
!tokens.contains("find_best"),
1355-
"did not expect legacy find_best in tokens"
1356-
);
1357-
assert!(
1358-
!tokens.contains("SolutionSize :: Invalid"),
1359-
"did not expect legacy invalid fallback in tokens"
1360-
);
1361-
}
1362-
13631331
#[test]
13641332
fn reduction_rejects_unexpected_attribute() {
13651333
let extra_attr = syn::Ident::new("extra", proc_macro2::Span::call_site());

‎scripts/test_website.py‎

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,45 @@ def test_graph_growth_labels_are_conservative_for_exact_signed_formulas(self):
190190
expect(self.page.locator('.path')).to_have_count(2)
191191
expect(self.page.get_by_role('button', name='Hide other routes', exact=True)).to_be_visible()
192192

193+
def test_typst_math_keeps_vector_glyphs_and_colors_in_both_themes(self):
194+
self.visit('problem/KSatisfiability?variant=k=K3')
195+
expect(self.page.locator('article.typst-detail')).to_be_visible()
196+
formula = self.page.locator('.typst-math > svg').filter(has=self.page.locator('g + g use')).first
197+
expect(formula).to_be_visible()
198+
self.page.evaluate('document.fonts.ready')
199+
# Include an intentional color and a fraction-like stroke alongside the real Typst glyphs.
200+
formula.locator('use').first.evaluate("node => node.setAttribute('fill', '#e15759')")
201+
formula.evaluate('''svg => {
202+
const line = document.createElementNS('http://www.w3.org/2000/svg', 'path');
203+
line.setAttribute('d', 'M0 .1H4'); line.setAttribute('stroke', '#000000');
204+
line.setAttribute('stroke-width', '.1'); svg.append(line);
205+
}''')
206+
for theme, ink, paper in [('dark', '#eef3e9', '#0b110d'), ('light', '#112011', '#ffffff')]:
207+
with self.subTest(theme=theme):
208+
self.page.evaluate('''({ink, paper}) => {
209+
document.documentElement.style.setProperty('--ink', ink);
210+
document.documentElement.style.setProperty('--paper', paper);
211+
}''', {'ink': ink, 'paper': paper})
212+
expect(formula.locator('use').first).to_have_css('fill', 'rgb(225, 87, 89)')
213+
actual = formula.screenshot()
214+
# Reference the same vectors with explicit theme paint and no rasterizing filter.
215+
saved = formula.evaluate('''(svg, ink) => {
216+
const painted = [...svg.querySelectorAll('[fill="#000000"], [stroke="#000000"]')];
217+
const saved = [svg.getAttribute('style'), painted.map(node => node.getAttribute('style'))];
218+
svg.style.filter = 'none';
219+
for (const node of painted) {
220+
if (node.getAttribute('fill') === '#000000') node.style.fill = ink;
221+
if (node.getAttribute('stroke') === '#000000') node.style.stroke = ink;
222+
}
223+
return saved;
224+
}''', ink)
225+
self.assertEqual(actual, formula.screenshot(), 'Theme styling changed the rendered math vectors')
226+
formula.evaluate('''(svg, [style, paints]) => {
227+
const restore = (node, value) => value === null ? node.removeAttribute('style') : node.setAttribute('style', value);
228+
restore(svg, style);
229+
[...svg.querySelectorAll('[fill="#000000"], [stroke="#000000"]')].forEach((node, i) => restore(node, paints[i]));
230+
}''', saved)
231+
193232
def test_accessibility_atlas(self):
194233
self.visit('atlas')
195234
expect(self.page.locator('.atlas-row').first).to_be_visible()
@@ -390,7 +429,7 @@ def test_graph_place_card_hands_a_reachable_problem_to_directions(self):
390429
self.page.locator('.act.primary').click()
391430
self.page.locator('#target').fill('QUBO')
392431
self.page.locator('#suggest button', has_text='QUBO').first.click()
393-
expect(self.page.locator('#results .summary strong')).to_contain_text('best route')
432+
expect(self.page.locator('#results .summary strong')).to_contain_text('size-bound candidate')
394433

395434
def test_accessibility_graph_desktop_drawer(self):
396435
self.page.goto(self.base + 'graph.html#directions')
@@ -525,7 +564,7 @@ def test_explore_defers_path_engine_until_directions(self):
525564
expect(self.page.locator('.path')).to_have_count(0)
526565
self.choose_endpoint('source', 'SAT')
527566
self.choose_endpoint('target', 'QUBO')
528-
expect(self.page.locator('#results .summary strong')).to_contain_text('best route')
567+
expect(self.page.locator('#results .summary strong')).to_contain_text('size-bound candidate')
529568
route = self.copy_route()
530569
self.assertEqual(route['path'][0]['from']['name'], 'Satisfiability')
531570
self.assertEqual(route['path'][-1]['to']['name'], 'QUBO')
@@ -1026,12 +1065,38 @@ def test_graph_sat_size_badges_finish_promptly_after_routes_arrive(self):
10261065
expect(self.page.locator('.path').first.locator('.size')).to_contain_text('n')
10271066

10281067
def test_graph_unavailable_parameters_keep_size_badges_unknown(self):
1068+
# Keep unavailable-field UI coverage independent of improvements to registry bounds.
1069+
nodes = [{'name': name, 'category': 'formula', 'variant': {}, 'default': True}
1070+
for name in ['Satisfiability', 'QUBO']]
1071+
known = {'certificate': 'num_vars^3', 'accuracy': {'kind': 'upper_bound'}}
1072+
unavailable = {'certificate': None, 'accuracy': {'kind': 'unavailable',
1073+
'reason': {'kind': 'unavailable', 'detail': 'Synthetic unavailable parameter'}}}
1074+
fields = {'num_vars': known, 'num_quadratic_terms': unavailable}
1075+
scene = {'nodes': nodes, 'edges': [{'source': 0, 'target': 1, 'witness': True,
1076+
'aggregate': False, 'turing': False, 'fields': fields}], 'aliases': {},
1077+
'layout': {'Satisfiability': {'x': 0, 'y': 0}, 'QUBO': {'x': 100, 'y': 70}}}
1078+
self.page.route('**/graph-scene.json.gz', lambda route: route.fulfill(
1079+
body=gzip.compress(json.dumps(scene).encode()), content_type='application/gzip'))
1080+
endpoint = lambda i: {'name': nodes[i]['name'], 'variant': {}}
1081+
paths = {'truncated': False, 'paths': [{'steps': 1,
1082+
'path': [{'from': endpoint(0), 'to': endpoint(1)}]}]}
1083+
comparison = {'profiles': [{'source_coordinates': ['num_vars'], 'fields': fields}],
1084+
'front': [1], 'counts': {'Dominated': 0, 'Equivalent': 0, 'Incomparable': 0, 'Unknown': 0}}
1085+
worker = 'self.onmessage = () => {' + ''.join('self.postMessage(' + json.dumps(reply) + ');'
1086+
for reply in [{'phase': 'paths', 'result': paths}, {'phase': 'comparison', 'result': comparison}]) + '};'
1087+
self.page.route('**/path-worker.js', lambda route: route.fulfill(body=worker, content_type='text/javascript'))
10291088
self.page.goto(self.base + 'graph.html#directions')
1030-
self.choose_endpoint('source', 'MVC')
1031-
self.page.locator('#source-options [aria-label="weight"]').get_by_role('button', name='One', exact=True).click()
1032-
self.choose_endpoint('target', 'LongestCommonSubsequence')
1033-
expect(self.page.locator('#results .summary strong')).to_contain_text('size-bound candidate', timeout=3000)
1034-
expect(self.page.locator('.path').first.locator('.size')).to_have_text('?', timeout=500)
1089+
expect(self.page.locator('#results .summary strong')).to_have_text('1 size-bound candidate')
1090+
expect(self.page.locator('.size.pending')).to_have_count(0)
1091+
expect(self.page.locator('.path .size')).to_have_text('?')
1092+
expect(self.page.locator('.path .size')).to_have_attribute('title', 'Size unavailable for one or more parameters')
1093+
summaries = self.page.locator('.growth').evaluate('''dl => Object.fromEntries(
1094+
[...dl.querySelectorAll('dt')].map(term=>[term.textContent,term.nextElementSibling.textContent]))''')
1095+
self.assertEqual(summaries, {'vars': 'O(vars³)', 'quadratic terms': 'unavailable'})
1096+
expect(self.page.locator('.steps .rule-link .oh')).to_have_text('?')
1097+
edge = self.page.locator('.scene-edge[data-edge="Satisfiability→QUBO"]')
1098+
expect(edge).to_have_count(1)
1099+
self.assertTrue({'route', 'e-unknown'} <= set(edge.get_attribute('class').split()))
10351100

10361101
def test_directions_preloads_engine_before_graph_initialization(self):
10371102
self.page.goto(self.base + 'graph.html#directions')

‎scripts/test_website_verification.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import tempfile
1414
import unittest
15+
from unittest.mock import patch
1516
from urllib.request import build_opener, ProxyHandler
1617
from urllib.parse import urlsplit
1718

@@ -74,7 +75,13 @@ def test_canceled_asset_request_does_not_print_a_server_traceback(self):
7475
def test_verification_only_report_does_not_claim_the_artifact_build_source(self):
7576
with tempfile.TemporaryDirectory() as directory:
7677
site = Path(directory)
77-
with self.assertRaises(FileNotFoundError):
78+
# This case checks failed-artifact provenance; the full verifier exercises these tools.
79+
run = subprocess.run
80+
def skip_tool_checks(command, **kwargs):
81+
if command[:2] in [["cargo", "test"], ["npm", "run"]]:
82+
return subprocess.CompletedProcess(command, 0)
83+
return run(command, **kwargs)
84+
with patch("check_website.subprocess.run", side_effect=skip_tool_checks), self.assertRaises(FileNotFoundError):
7885
check_website.check(site, build=False, open_questions=None)
7986
report = json.loads((site / "verification.json").read_text())
8087
self.assertEqual(report["verification"]["status"], "failed")

0 commit comments

Comments
 (0)