Skip to content

bugfix: wrong initialization of ConsensusADMM#248

Merged
mrava87 merged 3 commits intoPyLops:devfrom
tttamaki:dev_ConsensusADMM_fix
Mar 12, 2026
Merged

bugfix: wrong initialization of ConsensusADMM#248
mrava87 merged 3 commits intoPyLops:devfrom
tttamaki:dev_ConsensusADMM_fix

Conversation

@tttamaki
Copy link
Contributor

Fix initialization of $y_1, \ldots, y_m \in R^d$ to have a correct dimension.

The variable y should have a dimension of $m \times d$, where d is the dimension of x0, but it was incorrectly initialized to a dimension of $d$.

Before this change, the test passed incorrectly when $m \le d$ due to the following line;

x = ncp.stack([proxfs[i].prox(x_bar - y[i], tau) for i in range(m)])
# proxfs.shape == m, x_bar.shape == d, y[0],,,y[d-1] are scalar

But this will be an error when $m > d$ because out of index.
The test code in test_solver.py uses only $m=2$ proxfs with $d=$ par["m"] == 10, so I missed this bug.
I found this when I used $m=4$ proxfs and $d=2$ dimension of x0.

Notet that, in the second iteration, the dimension of y become $m \times d$ as expected because of the following line, so that the test have passed after iterations even with the wrong initialization.

y = y + x - x_bar  # y.shape == d, x.shape == (m, d), x_bar.shape == d  --> y.shape == (m, d)

- fix initialization of y_1, ..., y_m to have a correct dimension
Copilot AI review requested due to automatic review settings February 26, 2026 00:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the initialization of the dual variable y in the ConsensusADMM function. The variable was incorrectly initialized with dimension d instead of m × d, where m is the number of proximal operators and d is the dimension of the problem. This bug caused index out-of-bounds errors when m > d, though it went undetected in tests where m ≤ d due to numpy's broadcasting behavior in subsequent iterations that inadvertently corrected the shape.

Changes:

  • Fixed initialization of dual variable y from ncp.zeros_like(x0) to ncp.zeros((m, x0.shape[0])) to correctly allocate space for m dual variables, each of dimension d

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@mrava87 mrava87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tttamaki good catch. I just have a suggestion to ensure the dtype of y is still correctly setup 😄

@mrava87 mrava87 merged commit 4c2ddb4 into PyLops:dev Mar 12, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants