From 1755e90c0a31dfa54adc453aea81610f64a5f0e5 Mon Sep 17 00:00:00 2001 From: gghatano Date: Wed, 3 Jun 2026 20:04:19 +0900 Subject: [PATCH] Fix INDEPENDENT mechanism crash on duplicate cliques `independent.run_mechanism` builds `measurements` from `initial_measurements` (the one-way marginals that `data_generation_v2.generate` always passes in) and then appends a freshly measured one-way marginal for every attribute. When `initial_potentials` is not None (e.g. the empty CliqueVector returned by `constraints.get_initial_parameters` for the no-constraints case), the code calls `potentials.expand([m.clique for m in measurements])` with a clique list that now contains duplicate one-way cliques. With current `mbi`, `CliqueVector.expand` requires unique cliques and raises: ValueError: Cliques must be unique. so `dpsynth.generate(..., discrete_config=IndependentConfig())` fails. De-dup the clique list (order-preserving) before expanding. Measurements themselves are left unchanged, so the estimation/accounting are unaffected. --- dpsynth/discrete_mechanisms/independent.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dpsynth/discrete_mechanisms/independent.py b/dpsynth/discrete_mechanisms/independent.py index 046c411..82da37d 100644 --- a/dpsynth/discrete_mechanisms/independent.py +++ b/dpsynth/discrete_mechanisms/independent.py @@ -70,7 +70,13 @@ def run_mechanism( potentials = initial_potentials if potentials is not None: - potentials = potentials.expand([m.clique for m in measurements]) + # `measurements` can contain the same clique more than once (the one-way + # marginals passed in via `initial_measurements` plus the one-way marginals + # measured in the loop above). `CliqueVector.expand` requires unique cliques + # and otherwise raises "Cliques must be unique.", so de-duplicate while + # preserving order before expanding. + unique_cliques = list(dict.fromkeys(m.clique for m in measurements)) + potentials = potentials.expand(unique_cliques) model = mbi.estimation.mirror_descent( data.domain,