Skip to content

Commit

Permalink
remove box and fix typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Nov 7, 2024
1 parent 54b487c commit 6950476
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions crates/accelerate/src/circuit_library/multi_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Iterator<Item = PyResult<Instruction>>> =
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]
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/n_local/n_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [[]]
Expand Down

0 comments on commit 6950476

Please sign in to comment.