Skip to content
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

Port synth_cnot_phase_aam to Rust #12937

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8da594c
initial commit
MozammilQ Aug 10, 2024
193058b
added some code
MozammilQ Aug 10, 2024
2ae9379
refactor code
MozammilQ Aug 22, 2024
d7f41b7
Merge branch 'main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Aug 22, 2024
60379b2
done some cargo-clippy linting
MozammilQ Aug 23, 2024
671b634
added code
MozammilQ Aug 26, 2024
ae91425
added some more code
MozammilQ Aug 27, 2024
64ce56b
refactor code
MozammilQ Aug 27, 2024
fe01589
refactor code
MozammilQ Aug 27, 2024
1ecab6d
refactor code
MozammilQ Aug 28, 2024
a217522
refactor code
MozammilQ Aug 28, 2024
4a36e1e
refactor code
MozammilQ Aug 29, 2024
0b681f9
refactor code
MozammilQ Aug 29, 2024
d2142f6
refactor code
MozammilQ Aug 29, 2024
8982c2c
refactor code
MozammilQ Aug 29, 2024
032b8c2
removed associated python code
MozammilQ Aug 29, 2024
583ca17
rust lint
MozammilQ Aug 29, 2024
d1394f4
added release note; added docstring to rust algo
MozammilQ Aug 30, 2024
6956e0f
rust lint
MozammilQ Aug 30, 2024
0091c98
refactor code
MozammilQ Aug 30, 2024
92bf2aa
Merge branch 'main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Aug 30, 2024
6b2d31e
Merge branch 'main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Aug 31, 2024
156da41
applied suggestion partially
MozammilQ Sep 1, 2024
b236d62
reverting suggestions
MozammilQ Sep 2, 2024
d28da2a
added a test
MozammilQ Sep 4, 2024
4c32291
Merge branch 'Qiskit:main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Oct 28, 2024
1c7ad1e
Merge branch 'main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Oct 29, 2024
68917a0
Merge branch 'Qiskit:main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Nov 1, 2024
5973f85
replace vector with iterator
MozammilQ Nov 1, 2024
353e5ff
refactor code; lint
MozammilQ Nov 1, 2024
6262d16
refactor code
MozammilQ Nov 4, 2024
41a8906
refactor code
MozammilQ Nov 5, 2024
0cd01ce
refactor code
MozammilQ Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/accelerate/src/synthesis/linear/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::QiskitError;
use numpy::{IntoPyArray, PyArray2, PyReadonlyArray2, PyReadwriteArray2};
use pyo3::prelude::*;

mod pmh;
pub mod pmh;
pub mod utils;

#[pyfunction]
Expand Down
26 changes: 18 additions & 8 deletions crates/accelerate/src/synthesis/linear/pmh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use hashbrown::HashMap;
use ndarray::{s, Array1, Array2, ArrayViewMut2, Axis};
use numpy::PyReadonlyArray2;
use smallvec::smallvec;
use smallvec::{smallvec, SmallVec};
use std::cmp;

use qiskit_circuit::circuit_data::CircuitData;
Expand Down Expand Up @@ -159,7 +159,19 @@ pub fn synth_cnot_count_full_pmh(
section_size: Option<i64>,
) -> PyResult<CircuitData> {
let arrayview = matrix.as_array();
let mut mat: Array2<bool> = arrayview.to_owned();
let mat: Array2<bool> = arrayview.to_owned();
let num_qubits = mat.nrows();

let instructions = synth_pmh(mat, section_size);
CircuitData::from_standard_gates(py, num_qubits as u32, instructions, Param::Float(0.0))
}

type Instruction = (StandardGate, SmallVec<[Param; 3]>, SmallVec<[Qubit; 2]>);
pub fn synth_pmh(
mat: Array2<bool>,
section_size: Option<i64>,
) -> impl DoubleEndedIterator<Item = Instruction> {
let mut mat = mat;
let num_qubits = mat.nrows(); // is a quadratic matrix

// If given, use the user-specified input size. If None, we default to
Expand All @@ -179,17 +191,15 @@ pub fn synth_cnot_count_full_pmh(
let upper_cnots = lower_cnot_synth(mat.view_mut(), blocksize, true);

// iterator over the gates
let instructions = upper_cnots
.iter()
.map(|(i, j)| (*j, *i))
upper_cnots
.into_iter()
.map(|(i, j)| (j, i))
.chain(lower_cnots.into_iter().rev())
.map(|(ctrl, target)| {
(
StandardGate::CXGate,
smallvec![],
smallvec![Qubit(ctrl as u32), Qubit(target as u32)],
)
});

CircuitData::from_standard_gates(py, num_qubits as u32, instructions, Param::Float(0.0))
})
}
Loading