Remove duplicated method on TwoQubitBasisDecomposer#15835
Remove duplicated method on TwoQubitBasisDecomposer#15835alexanderivrii merged 1 commit intoQiskit:mainfrom
Conversation
|
One or more of the following people are relevant to this code:
|
ShellyGarion
left a comment
There was a problem hiding this comment.
Copying here a few comments from #15833, and a few more comments about the reorganization of the files that may slightly be improved.
perhpas we can combine these small changes as part of this PR?
|
|
||
| const PI2: f64 = PI / 2.; | ||
| const PI4: f64 = PI / 4.; | ||
| const TWO_PI: f64 = 2.0 * PI; |
There was a problem hiding this comment.
perhaps it's worth to use the usual constants:
FRAC_PI_2, FRAC_PI_4, FRAC_2_PI
| } | ||
| } | ||
|
|
||
| fn u4_to_su4(u4: ArrayView2<Complex64>) -> (Array2<Complex64>, f64) { |
There was a problem hiding this comment.
perhaps this function could also be moved to common?
| (su4, phase_factor.arg()) | ||
| } | ||
|
|
||
| fn real_trace_transform(mat: ArrayView2<Complex64>) -> Array2<Complex64> { |
There was a problem hiding this comment.
could you please add a docstring to this function?
perhaps this function could also be moved to common?
| Ok((real_map, circ)) | ||
| } | ||
|
|
||
| fn compute_unitary(sequence: &TwoQubitSequenceVec, global_phase: f64) -> Array2<Complex64> { |
There was a problem hiding this comment.
perhaps this function could also be moved to common?
| use super::gate_sequence::TwoQubitGateSequence; | ||
| use super::weyl_decomposition::{Specialization, TwoQubitWeylDecomposition}; | ||
|
|
||
| const PI2: f64 = PI / 2.; |
There was a problem hiding this comment.
again, perhaps we can use here FRAC_PI_2 ?
|
|
||
| static IPZ: GateArray1Q = [[IM, C_ZERO], [C_ZERO, M_IM]]; | ||
| static IPY: GateArray1Q = [[C_ZERO, C_ONE], [C_M_ONE, C_ZERO]]; | ||
| static IPX: GateArray1Q = [[C_ZERO, IM], [IM, C_ZERO]]; |
There was a problem hiding this comment.
again, perhaps these should be in common?
| // Python space. | ||
| const TWO_QUBIT_SEQUENCE_DEFAULT_CAPACITY: usize = 21; | ||
|
|
||
| static IPZ: GateArray1Q = [[IM, C_ZERO], [C_ZERO, M_IM]]; |
There was a problem hiding this comment.
I think this also appears elsewhere in the code, so it's better to move it to common.
| } | ||
| } | ||
|
|
||
| static K12R_ARR: GateArray1Q = [ |
There was a problem hiding this comment.
perhaps this should be moved to common?
| [c64(-FRAC_1_SQRT_2, 0.), c64(0., -FRAC_1_SQRT_2)], | ||
| ]; | ||
|
|
||
| static K12L_ARR: GateArray1Q = [ |
There was a problem hiding this comment.
perhaps this should be moved to common?
| } | ||
|
|
||
| #[pyfunction] | ||
| pub fn local_equivalence(weyl: PyReadonlyArray1<f64>) -> PyResult<[f64; 3]> { |
There was a problem hiding this comment.
it's worth to add some docstring to this fucntion
This commit removes a duplicated method implementation on the TwoQubitBasisDecomposer. The struct had two methods, call_inner and generate_sequences, which were almost line for line identical. I believe this occured during a rebase when two concurrently developed PRs were touching the same file and the rebase was a bit off after one merged which resulted in the methods being duplicated. This was missed for quite some time and is what prompted Qiskit#15833 because the original two_qubit_decompose.rs file was so big it was very easy to overlook this duplication. This commit deletes the generate_sequence implementation and just uses the call_inner function.
73353ae to
84e88a7
Compare
|
@ShellyGarion none of your review comments apply to the contents of this PR. They all were on the parent of this PR #15833 (although I would have said on that review I wouldn't want to change the code while making the split) this PR is a very simple removal of the duplicated code. If you have suggested improvements for the two qubit decomposer code I'd suggest opening your own PR making the improvements. |
ShellyGarion
left a comment
There was a problem hiding this comment.
I approve this change and will open another PR for code reorganization and small fixes.
alexanderivrii
left a comment
There was a problem hiding this comment.
LGTM! But not merging in case Shelly has additional comments.
| .min_by(|(_idx1, fid1), (_idx2, fid2)| fid2.partial_cmp(fid1).unwrap()) | ||
| .unwrap() | ||
| .0; | ||
| let best_nbasis = _num_basis_uses.unwrap_or(best_nbasis as u8); |
There was a problem hiding this comment.
As far as I can tell, there is no real difference between the two functions, while the surviving function is more efficient handling this line - does not eagerly compute best_nbasis.
There was a problem hiding this comment.
Ah, Shelly has already approved the changes as well. :)
Summary
This commit removes a duplicated method implementation on the
TwoQubitBasisDecomposer. The struct had two methods, call_inner and
generate_sequences, which were almost line for line identical. I believe
this occured during a rebase when two concurrently developed PRs were
touching the same file and the rebase was a bit off after one merged
which resulted in the methods being duplicated. This was missed for
quite some time and is what prompted #15833 because the original
two_qubit_decompose.rs file was so big it was very easy to overlook this
duplication. This commit deletes the generate_sequence implementation
and just uses the call_inner function.
Details and comments
This PR is based on top of #15833 and will need to be rebased after that merges. In the meantime you can view the contents of this PR by looking at the HEAD commit on this PR's branch: 73353aeRebased now