Skip to content

Commit

Permalink
Merge branch 'main' into remove-pulse
Browse files Browse the repository at this point in the history
  • Loading branch information
eliarbel authored Mar 5, 2025
2 parents 1848146 + 65d041b commit 2907895
Show file tree
Hide file tree
Showing 35 changed files with 2,122 additions and 870 deletions.
353 changes: 259 additions & 94 deletions crates/accelerate/src/circuit_library/pauli_evolution.rs

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions crates/accelerate/src/circuit_library/pauli_feature_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,13 @@ fn _get_evolution_layer<'a>(
// to call CircuitData::from_packed_operations. This is needed since we might
// have to interject barriers, which are not a standard gate and prevents us
// from using CircuitData::from_standard_gates.
let evo = pauli_evolution::pauli_evolution(
let evo = pauli_evolution::sparse_term_evolution(
pauli,
indices.into_iter().rev().collect(),
multiply_param(&angle, alpha, py),
true,
false,
)
.map(|(gate, params, qargs)| {
(gate.into(), params, qargs.to_vec(), vec![] as Vec<Clbit>)
})
.collect::<Vec<Instruction>>();
);
insts.extend(evo);
}
}
Expand Down
27 changes: 21 additions & 6 deletions crates/accelerate/src/consolidate_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ use num_complex::Complex64;
use numpy::PyReadonlyArray2;
use pyo3::intern;
use pyo3::prelude::*;
use rustworkx_core::petgraph::stable_graph::NodeIndex;
use smallvec::smallvec;

use qiskit_circuit::circuit_data::CircuitData;
use qiskit_circuit::dag_circuit::DAGCircuit;
use qiskit_circuit::gate_matrix::{ONE_QUBIT_IDENTITY, TWO_QUBIT_IDENTITY};
use qiskit_circuit::imports::{QI_OPERATOR, QUANTUM_CIRCUIT};
use qiskit_circuit::operations::{ArrayType, Operation, Param, UnitaryGate};
use qiskit_circuit::packed_instruction::PackedOperation;
use qiskit_circuit::Qubit;
use rustworkx_core::petgraph::stable_graph::NodeIndex;
use smallvec::smallvec;

use crate::convert_2q_block_matrix::{blocks_to_matrix, get_matrix_from_inst};
use crate::euler_one_qubit_decomposer::matmul_1q;
use crate::nlayout::PhysicalQubit;
use crate::target_transpiler::Target;
use crate::two_qubit_decompose::TwoQubitBasisDecomposer;
use crate::two_qubit_decompose::{TwoQubitBasisDecomposer, TwoQubitControlledUDecomposer};

#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, FromPyObject)]
pub enum DecomposerType {
TwoQubitBasis(TwoQubitBasisDecomposer),
TwoQubitControlledU(TwoQubitControlledUDecomposer),
}

fn is_supported(
target: Option<&Target>,
Expand Down Expand Up @@ -61,7 +67,7 @@ const MAX_2Q_DEPTH: usize = 20;
pub(crate) fn consolidate_blocks(
py: Python,
dag: &mut DAGCircuit,
decomposer: &TwoQubitBasisDecomposer,
decomposer: DecomposerType,
basis_gate_name: &str,
force_consolidate: bool,
target: Option<&Target>,
Expand Down Expand Up @@ -211,8 +217,17 @@ pub(crate) fn consolidate_blocks(
];
let matrix = blocks_to_matrix(py, dag, &block, block_index_map).ok();
if let Some(matrix) = matrix {
let num_basis_gates = match decomposer {
DecomposerType::TwoQubitBasis(ref decomp) => {
decomp.num_basis_gates_inner(matrix.view())
}
DecomposerType::TwoQubitControlledU(ref decomp) => {
decomp.num_basis_gates_inner(matrix.view())?
}
};

if force_consolidate
|| decomposer.num_basis_gates_inner(matrix.view()) < basis_count
|| num_basis_gates < basis_count
|| block.len() > MAX_2Q_DEPTH
|| (basis_gates.is_some() && outside_basis)
|| (target.is_some() && outside_basis)
Expand Down
Loading

0 comments on commit 2907895

Please sign in to comment.