-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize ConsolidateBlocks
pass
#10365
Conversation
- Will default to previous method when blocks have more than 2 qubits. - This is a temporary measure.
ConsolidateBlocks
passConsolidateBlocks
pass
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 5616076303
💛 - Coveralls |
The Actually I believe @chriseclectic orginally was using matmul in Operator but switched to einsum for speed but perhaps that was just based on larger matrices? |
Erick: this PR is deliberately meant to take over some of what
|
Can you show the profile result in table format sorted by cumtime and tottime for the top ~20 rows? |
@ewinston This is for the optimized version: |
@raynelfss It appears like the profiling includes other passes besides the one under test which makes the output a little hard to interpret. Don't worry about it for now though since we're just taking the step of moving the block_to_matrix to transpiler/passes/utils. |
…-terra into blocks-optimize
Returns: | ||
NDArray: Matrix representation of the block of operations. | ||
""" | ||
matrix = identity(2 ** len(block_index_map), dtype=complex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception should be raised if the dimension of matrix != 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, it would be better to just throw an exception whenever len(block_index_map) != 2
. Since earlier in the code we know that block_index_map
comes from the following operation:
Which takes block_qargs
(The set of all qubits in the block) as an argument and returns a mapped dictionary of the same length. Before we call _block_to_matrix
we will check that len(block_qargs) <= 2
to call it, otherwise, the old method will be used. As shown here:
So it would be better to just add an exception at the beginning of block_to_matrix
that says if the length of block_index_length
exceeds 2 then throw an error. Which would cover for cases in which the matrix has a dimension that exceeds 2x2.
block_index_length = len(block_index_map) | ||
if block_index_length != 2: | ||
raise QiskitError( | ||
"This function can only operate with blocks of 2 qubits or less." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "or less" should be removed.
Head branch was pushed to by a user without write access
Summary
Tries to address #8779
The following commits attempt to speedup the
ConsolidateBlocks
pass by calculating the unitary of each block inside of the pass rather than passing it as aQuantumCircuit
and converting it to anOperator
, which is redundant.Details and comments
Known issues:
When a circuit is generated from a qasm file, some non-traditional gates will not have a definedFixed in 653e23c.to_matrix
method and the algorithm will throw an exception.Performance
The following is an example with a 1024 qubit random circuit of depth 128.
ConsolidateBlocks
:ConsolidateBlocks
: