Skip to content

Commit

Permalink
Merge branch 'main' into move-equivalence
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Jul 1, 2024
2 parents 77dbec8 + 5deed7a commit cd0b36e
Show file tree
Hide file tree
Showing 51 changed files with 1,902 additions and 675 deletions.
47 changes: 40 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ num-complex = "0.4"
ndarray = "^0.15.6"
numpy = "0.21.0"
smallvec = "1.13"
thiserror = "1.0"

# Most of the crates don't need the feature `extension-module`, since only `qiskit-pyext` builds an
# actual C extension (the feature disables linking in `libpython`, which is forbidden in Python
Expand Down
4 changes: 0 additions & 4 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ scipy<1.11; python_version<'3.12'
# See https://github.com/Qiskit/qiskit/issues/12655 for current details.
scipy==1.13.1; python_version=='3.12'

# Rustworkx 0.15.0 contains a bug that breaks graphviz-related tests.
# See https://github.com/Qiskit/rustworkx/pull/1229 for the fix.
rustworkx==0.14.2

# z3-solver from 4.12.3 onwards upped the minimum macOS API version for its
# wheels to 11.7. The Azure VM images contain pre-built CPythons, of which at
# least CPython 3.8 was compiled for an older macOS, so does not match a
Expand Down
3 changes: 2 additions & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ ahash = "0.8.11"
num-traits = "0.2"
num-complex.workspace = true
num-bigint = "0.4"
rustworkx-core = "0.14"
rustworkx-core = "0.15"
faer = "0.19.1"
itertools = "0.13.0"
qiskit-circuit.workspace = true
thiserror.workspace = true

[dependencies.smallvec]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/accelerate/src/dense_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub fn best_subset_inner(
SubsetResult {
count: 0,
map: Vec::new(),
error: std::f64::INFINITY,
error: f64::INFINITY,
subgraph: Vec::new(),
}
};
Expand Down
55 changes: 12 additions & 43 deletions crates/accelerate/src/euler_one_qubit_decomposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ use std::f64::consts::PI;
use std::ops::Deref;
use std::str::FromStr;

use pyo3::exceptions::{PyIndexError, PyValueError};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3::types::PyString;
use pyo3::types::{PyList, PyString};
use pyo3::wrap_pyfunction;
use pyo3::Python;

use ndarray::prelude::*;
use numpy::PyReadonlyArray2;
use pyo3::pybacked::PyBackedStr;

use qiskit_circuit::slice::{PySequenceIndex, SequenceIndex};
use qiskit_circuit::util::c64;
use qiskit_circuit::SliceOrInt;

pub const ANGLE_ZERO_EPSILON: f64 = 1e-12;

Expand Down Expand Up @@ -97,46 +97,15 @@ impl OneQubitGateSequence {
Ok(self.gates.len())
}

fn __getitem__(&self, py: Python, idx: SliceOrInt) -> PyResult<PyObject> {
match idx {
SliceOrInt::Slice(slc) => {
let len = self.gates.len().try_into().unwrap();
let indices = slc.indices(len)?;
let mut out_vec: Vec<(String, SmallVec<[f64; 3]>)> = Vec::new();
// Start and stop will always be positive the slice api converts
// negatives to the index for example:
// list(range(5))[-1:-3:-1]
// will return start=4, stop=2, and step=-1
let mut pos: isize = indices.start;
let mut cond = if indices.step < 0 {
pos > indices.stop
} else {
pos < indices.stop
};
while cond {
if pos < len as isize {
out_vec.push(self.gates[pos as usize].clone());
}
pos += indices.step;
if indices.step < 0 {
cond = pos > indices.stop;
} else {
cond = pos < indices.stop;
}
}
Ok(out_vec.into_py(py))
}
SliceOrInt::Int(idx) => {
let len = self.gates.len() as isize;
if idx >= len || idx < -len {
Err(PyIndexError::new_err(format!("Invalid index, {idx}")))
} else if idx < 0 {
let len = self.gates.len();
Ok(self.gates[len - idx.unsigned_abs()].to_object(py))
} else {
Ok(self.gates[idx as usize].to_object(py))
}
}
fn __getitem__(&self, py: Python, idx: PySequenceIndex) -> PyResult<PyObject> {
match idx.with_len(self.gates.len())? {
SequenceIndex::Int(idx) => Ok(self.gates[idx].to_object(py)),
indices => Ok(PyList::new_bound(
py,
indices.iter().map(|pos| self.gates[pos].to_object(py)),
)
.into_any()
.unbind()),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/accelerate/src/nlayout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl NLayout {
physical_qubits: usize,
) -> Self {
let mut res = NLayout {
virt_to_phys: vec![PhysicalQubit(std::u32::MAX); virtual_qubits],
phys_to_virt: vec![VirtualQubit(std::u32::MAX); physical_qubits],
virt_to_phys: vec![PhysicalQubit(u32::MAX); virtual_qubits],
phys_to_virt: vec![VirtualQubit(u32::MAX); physical_qubits],
};
for (virt, phys) in qubit_indices {
res.virt_to_phys[virt.index()] = phys;
Expand Down Expand Up @@ -184,7 +184,7 @@ impl NLayout {

#[staticmethod]
pub fn from_virtual_to_physical(virt_to_phys: Vec<PhysicalQubit>) -> PyResult<Self> {
let mut phys_to_virt = vec![VirtualQubit(std::u32::MAX); virt_to_phys.len()];
let mut phys_to_virt = vec![VirtualQubit(u32::MAX); virt_to_phys.len()];
for (virt, phys) in virt_to_phys.iter().enumerate() {
phys_to_virt[phys.index()] = VirtualQubit(virt.try_into()?);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/accelerate/src/stochastic_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ fn swap_trial(
let mut new_cost: f64;
let mut dist: f64;

let mut optimal_start = PhysicalQubit::new(std::u32::MAX);
let mut optimal_end = PhysicalQubit::new(std::u32::MAX);
let mut optimal_start_qubit = VirtualQubit::new(std::u32::MAX);
let mut optimal_end_qubit = VirtualQubit::new(std::u32::MAX);
let mut optimal_start = PhysicalQubit::new(u32::MAX);
let mut optimal_end = PhysicalQubit::new(u32::MAX);
let mut optimal_start_qubit = VirtualQubit::new(u32::MAX);
let mut optimal_end_qubit = VirtualQubit::new(u32::MAX);

let mut scale = Array2::zeros((num_qubits, num_qubits));

Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn swap_trials(
// unless force threads is set.
let run_in_parallel = getenv_use_multiple_threads();

let mut best_depth = std::usize::MAX;
let mut best_depth = usize::MAX;
let mut best_edges: Option<EdgeCollection> = None;
let mut best_layout: Option<NLayout> = None;
if run_in_parallel {
Expand Down
Loading

0 comments on commit cd0b36e

Please sign in to comment.