Skip to content

Remove duplicated method on TwoQubitBasisDecomposer#15835

Merged
alexanderivrii merged 1 commit intoQiskit:mainfrom
mtreinish:remove-duplicated-sequence-generation
Mar 23, 2026
Merged

Remove duplicated method on TwoQubitBasisDecomposer#15835
alexanderivrii merged 1 commit intoQiskit:mainfrom
mtreinish:remove-duplicated-sequence-generation

Conversation

@mtreinish
Copy link
Copy Markdown
Member

@mtreinish mtreinish commented Mar 19, 2026

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: 73353ae Rebased now

@mtreinish mtreinish requested a review from a team as a code owner March 19, 2026 01:33
@mtreinish mtreinish added Changelog: None Do not include in the GitHub Release changelog. synthesis Rust This PR or issue is related to Rust code in the repository labels Mar 19, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core
  • @levbishop

@ShellyGarion ShellyGarion added this to the 2.5.0 milestone Mar 19, 2026
Copy link
Copy Markdown
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps this function could also be moved to common?

(su4, phase_factor.arg())
}

fn real_trace_transform(mat: ArrayView2<Complex64>) -> Array2<Complex64> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this also appears elsewhere in the code, so it's better to move it to common.

}
}

static K12R_ARR: GateArray1Q = [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps this should be moved to common?

[c64(-FRAC_1_SQRT_2, 0.), c64(0., -FRAC_1_SQRT_2)],
];

static K12L_ARR: GateArray1Q = [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps this should be moved to common?

}

#[pyfunction]
pub fn local_equivalence(weyl: PyReadonlyArray1<f64>) -> PyResult<[f64; 3]> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.
@mtreinish mtreinish force-pushed the remove-duplicated-sequence-generation branch from 73353ae to 84e88a7 Compare March 23, 2026 11:57
@mtreinish
Copy link
Copy Markdown
Member Author

@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.

Copy link
Copy Markdown
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

I approve this change and will open another PR for code reorganization and small fixes.

Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, Shelly has already approved the changes as well. :)

@alexanderivrii alexanderivrii added this pull request to the merge queue Mar 23, 2026
Merged via the queue into Qiskit:main with commit 572045f Mar 23, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.5 Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository synthesis

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants