diff --git a/crates/accelerate/src/circuit_library/multi_local.rs b/crates/accelerate/src/circuit_library/multi_local.rs index 9b15c40551a..dd75ebbcc5e 100644 --- a/crates/accelerate/src/circuit_library/multi_local.rs +++ b/crates/accelerate/src/circuit_library/multi_local.rs @@ -195,35 +195,35 @@ pub fn n_local( // it returns an empty iterator. For conveniently injecting barriers in-between operations. let maybe_barrier = MaybeBarrier::new(py, num_qubits, insert_barriers)?; - let mut packed_insts: Box>> = - Box::new((0..reps).flat_map(|layer| { - rotation_layer( - py, - num_qubits, - rotation_blocks, - ledger.get_parameters(LayerType::Rotation, layer), - &skipped_qubits, - ) - .chain(maybe_barrier.get()) - .chain(entanglement_layer( - py, - entanglement.get_layer(layer), - entanglement_blocks, - ledger.get_parameters(LayerType::Entangle, layer), - )) - .chain(maybe_barrier.get()) - })); + let packed_insts = (0..reps).flat_map(|layer| { + rotation_layer( + py, + num_qubits, + rotation_blocks, + ledger.get_parameters(LayerType::Rotation, layer), + &skipped_qubits, + ) + .chain(maybe_barrier.get()) + .chain(entanglement_layer( + py, + entanglement.get_layer(layer), + entanglement_blocks, + ledger.get_parameters(LayerType::Entangle, layer), + )) + .chain(maybe_barrier.get()) + }); if !skip_final_rotation_layer { - packed_insts = Box::new(packed_insts.chain(rotation_layer( + let packed_insts = packed_insts.chain(rotation_layer( py, num_qubits, rotation_blocks, ledger.get_parameters(LayerType::Rotation, reps), &skipped_qubits, - ))) + )); + CircuitData::from_packed_operations(py, num_qubits, 0, packed_insts, Param::Float(0.0)) + } else { + CircuitData::from_packed_operations(py, num_qubits, 0, packed_insts, Param::Float(0.0)) } - - CircuitData::from_packed_operations(py, num_qubits, 0, packed_insts, Param::Float(0.0)) } #[pyfunction] diff --git a/qiskit/circuit/library/n_local/n_local.py b/qiskit/circuit/library/n_local/n_local.py index b7e064e9ac0..b8f8d317669 100644 --- a/qiskit/circuit/library/n_local/n_local.py +++ b/qiskit/circuit/library/n_local/n_local.py @@ -1313,7 +1313,7 @@ def _normalize_entanglement( if isinstance(entanglement, str): return [entanglement] * num_entanglement_blocks - elif isinstance(entanglement, Iterable): + elif not callable(entanglement): # handle edge cases when entanglement is set to an empty list if len(entanglement) == 0: return [[]]