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 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 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
75bc902
removed impl Iterator and applied from_fn
MozammilQ Nov 16, 2024
62aef8c
Merge branch 'Qiskit:main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Nov 16, 2024
477e62e
removed moving from into_iter to vec to into_iter
MozammilQ Nov 16, 2024
f5a92c9
applied Julien suggestions
MozammilQ Nov 17, 2024
93375c5
applied some suggestions by Ivrii
MozammilQ Jan 12, 2025
cb2170c
typo added suggestion by Julien Gacon
MozammilQ Jan 13, 2025
2bdaaae
Merge branch 'Qiskit:main' into port-synth_cnot_phase_aam-to-rust
MozammilQ Jan 13, 2025
843c220
renamed variables; added comments
MozammilQ Jan 14, 2025
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
30 changes: 20 additions & 10 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 @@ -158,8 +158,20 @@ pub fn synth_cnot_count_full_pmh(
matrix: PyReadonlyArray2<bool>,
section_size: Option<i64>,
) -> PyResult<CircuitData> {
let arrayview = matrix.as_array();
let mut mat: Array2<bool> = arrayview.to_owned();
let mat: Array2<bool> = matrix.as_array().to_owned();
let num_qubits = mat.nrows();
let section_size: Option<usize> =
section_size.and_then(|num| if num >= 0 { Some(num as usize) } else { None });

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(
mut mat: Array2<bool>,
section_size: Option<usize>,
) -> impl DoubleEndedIterator<Item = Instruction> {
let num_qubits = mat.nrows(); // is a quadratic matrix

// If given, use the user-specified input size. If None, we default to
Expand All @@ -169,7 +181,7 @@ pub fn synth_cnot_count_full_pmh(
// until ~100 qubits.
let alpha = 0.56;
let blocksize = match section_size {
Some(section_size) => section_size as usize,
Some(section_size) => section_size,
None => std::cmp::max(2, (alpha * (num_qubits as f64).log2()).floor() as usize),
};

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()
MozammilQ marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading