Skip to content

fix: remove custom MultiControlledX.__repr__ - #10190

Open
andrijapau wants to merge 7 commits into
mainfrom
fix/update-mcx-repr
Open

andrijapau wants to merge 7 commits into
mainfrom
fix/update-mcx-repr

Conversation

@andrijapau

@andrijapau andrijapau commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Context:

This PR improves MCX's repr to use the base Operator.__repr__ to improve debuggability.

[sc-130135]

@andrijapau andrijapau changed the title remove MultiControlledX custom repr fix: remove custom MultiControlledX.__repr__ Sep 24, 2026
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (7005ec8) to head (7d506f3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10190      +/-   ##
==========================================
- Coverage   99.41%   99.41%   -0.01%     
==========================================
  Files         603      603              
  Lines       66975    66967       -8     
==========================================
- Hits        66580    66572       -8     
  Misses        395      395              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

)

def __repr__(self):
params = [f"wires={self.wires}"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only notable change - the rest is qp.math -> math.

Comment thread pennylane/core/qscript.py
>>> mapped_circuit = circuit.map_to_standard_wires()
>>> mapped_circuit.circuit
[MultiControlledX(wires=[0, 1, 2, 3]), probs(wires=[3, 4, 5])]
[MultiControlledX(wires=[0, 1, 2, 3], control_values=[ True True True], work_wires=[6, 5], work_wire_type=borrowed), probs(wires=[3, 4, 5])]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we keep it so that trivial control_values don't get printed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For arbitrary controlled operators, we only print the control values if there are tracers, it is abstract, or there are zero-controls. For consistency, I would say that we should do the same for MCX

Comment thread doc/releases/changelog-dev.md Outdated
>>> pprint(ops)
[StatePrep(array([0.707..., 0.707...]), wires=[1]),
MultiControlledX(wires=[0, 1, 2], control_values=[False, True]),
MultiControlledX(wires=[0, 1, 2], control_values=[False True], work_wires=[], work_wire_type=borrowed),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it also makes sense to override __repr__ so that we can print control_values.tolist() instead of the array, which should make the formatting a bit nicer

Co-authored-by: Mudit Pandey <18223836+mudit2812@users.noreply.github.com>
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.

2 participants