Skip to content

Conversation

ihincks
Copy link
Contributor

@ihincks ihincks commented May 16, 2025

Summary

This PR excepts BoxOp from the logic that causes ControlFlowOps to render sequentially in visualization.

Details and comments

The rational is that boxes don't share other concerns like having multiple blocks or direct classical dependencies (though their contents might). However, I can't pretend to understand completely the implications of this change given the complexity of the visualization folder that I am new to. More than anything, I haven't been able to find examples where this exception causes a problem, but it's easy to find examples that look way better with this change.

A couple of illustrative examples.

1.

WITH this PR:
image

WITHOUT this PR:
image

2.

WITH this PR:
image

WITHOUT this PR:
image

3.

WITH this PR:
image

WITHOUT this PR:
image

@ihincks ihincks requested review from nonhermitian and a team as code owners May 16, 2025 14:05
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

@enavarro51
Copy link
Contributor

@ihincks A little bit of history. When we were developing the visualizations for ControlFlowOps, we ran into trouble when there were gates above and below the CFOs. Ordinary gates are placed on a grid and gate widths are created in increments of a basic gate size.

CFOs, because of their complex nature, nesting, and various internal text uses only use the grid for the left-hand placement. If we hadn't done that, the CFOs would have been much larger with a great deal of empty space inside. Each nested CFO has its own grid for the gates inside it. What this means is that the 'condition' line going down, as in your ex. 2, may appear anywhere horizontally, including through a gate below.

In addition, there is a whole section of code and data that figures out how to place the non-CFO gates when the qubit lines wrap to a new set and this code does not work if gates are above or below a CFO.

So the decision was made to do the good enough solution with the thought that the wrapping and condition line problems might be handled later.

Bottom line is that your 'span' solution probably wouldn't work with a complex circuit with gates above and below the BoxOps. (I'm just assuming this from memory, but haven't actually tried your solution).

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for the change Ian, certainly from the examples I think this is a big improvement, and I don't immediately remember any of the considerations around line-splitting that would cause the box drawing like this to be a problem.

There's one text-visualisation test that needs a fix in the code, and I suspect that there might be reference-image tests in tests/visual that fail, but for those, it's typically easiest to push up a commit, let the CI run, then download the test artefact, which includes the generated images, and add those to the PR. I don't think we need to add new tests, because the existing ones seem to be covering it already, we just have to update the source of truth.

Can you add a one-sentence release-note?

@jakelishman
Copy link
Member

Thanks for the history Ed - you've got a better memory than I do about that. I guess let's try merging this and then fix the bugs when we find them again - the new BoxOp is likely to get a lot more use in the near future than control-flow ops have had so far (though that also might change in the next year), so getting something that's good for the 90% case in now is probably the right call.

@coveralls
Copy link

coveralls commented May 16, 2025

Pull Request Test Coverage Report for Build 15076434238

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 14 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.002%) to 88.3%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.23%
crates/transpiler/src/passes/unitary_synthesis.rs 1 94.85%
crates/qasm2/src/lex.rs 5 91.98%
crates/circuit/src/symbol_expr.rs 7 75.19%
Totals Coverage Status
Change from base Build 15073202664: -0.002%
Covered Lines: 78447
Relevant Lines: 88841

💛 - Coveralls

@ihincks ihincks requested a review from jakelishman May 16, 2025 19:59
@ihincks
Copy link
Contributor Author

ihincks commented May 16, 2025

Thanks for the background info @enavarro51 ! I'll keep my eye out for regressions as I plan to use this feature quite a bit over the coming months.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks, Ian

@jakelishman jakelishman enabled auto-merge May 16, 2025 20:17
@jakelishman jakelishman added this pull request to the merge queue May 16, 2025
Merged via the queue into Qiskit:main with commit 3f97420 May 16, 2025
24 checks passed
@ihincks ihincks deleted the parallel-boxes branch May 16, 2025 23:35
@eliarbel eliarbel added this to the 2.1.0 milestone Jun 3, 2025
@eliarbel eliarbel added the Changelog: New Feature Include in the "Added" section of the changelog label Jun 3, 2025
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
* Change the qubit span of boxes to not be all qubits

* update comment

* better docstring

* fix broken test

* update reference plot

* reno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants