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

Invalidate PackedInstruction cache upon modification #13543

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 10 additions & 25 deletions crates/accelerate/src/barrier_before_final_measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub fn barrier_before_final_measurements(
let NodeType::Operation(ref inst) = dag.dag()[*node] else {
unreachable!();
};
if !FINAL_OP_NAMES.contains(&inst.op.name()) {
if !FINAL_OP_NAMES.contains(&inst.op().name()) {
return false;
}
let is_final_op = dag.bfs_successors(*node).all(|(_, child_successors)| {
!child_successors.iter().any(|suc| match dag.dag()[*suc] {
NodeType::Operation(ref suc_inst) => {
!FINAL_OP_NAMES.contains(&suc_inst.op.name())
!FINAL_OP_NAMES.contains(&suc_inst.op().name())
}
_ => false,
})
Expand Down Expand Up @@ -84,29 +84,14 @@ pub fn barrier_before_final_measurements(
instruction: new_barrier.unbind(),
};
let qargs: Vec<Qubit> = (0..dag.num_qubits() as u32).map(Qubit).collect();
#[cfg(feature = "cache_pygates")]
{
dag.apply_operation_back(
py,
PackedOperation::from_instruction(Box::new(new_barrier_py_inst)),
qargs.as_slice(),
&[],
None,
ExtraInstructionAttributes::new(label, None, None, None),
Some(new_barrier.unbind()),
)?;
}
#[cfg(not(feature = "cache_pygates"))]
{
dag.apply_operation_back(
py,
PackedOperation::from_instruction(Box::new(new_barrier_py_inst)),
qargs.as_slice(),
&[],
None,
ExtraInstructionAttributes::new(label, None, None, None),
)?;
}
dag.apply_operation_back(
py,
PackedOperation::from_instruction(Box::new(new_barrier_py_inst)),
qargs.as_slice(),
&[],
None,
ExtraInstructionAttributes::new(label, None, None, None),
)?;
for inst in final_packed_ops {
dag.push_back(py, inst)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(crate) fn basis_search(
let mut cost_tot = 0;
let borrowed_cost = opt_cost_map.borrow();
for instruction in edge_data.rule.circuit.0.iter() {
let instruction_op = instruction.op.view();
let instruction_op = instruction.op().view();
cost_tot += borrowed_cost[&(
instruction_op.name().to_string(),
instruction_op.num_qubits(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub(super) fn compose_transforms<'a>(
Some(gate_obj.params)
},
gate_obj.extra_attrs,
#[cfg(feature = "cache_pygates")]
Some(gate.into()),
)?;
mapped_instructions.insert((gate_name, gate_num_qubits), (placeholder_params, dag));

Expand All @@ -86,7 +84,7 @@ pub(super) fn compose_transforms<'a>(
.filter_map(|node| {
if let Some(NodeType::Operation(op)) = dag.dag().node_weight(node) {
if (gate_name.as_str(), *gate_num_qubits)
== (op.op.name(), op.op.num_qubits())
== (op.op().name(), op.op().num_qubits())
{
Some((
node,
Expand Down Expand Up @@ -144,11 +142,11 @@ fn get_gates_num_params(
for node in dag.op_nodes(true) {
if let Some(NodeType::Operation(op)) = dag.dag().node_weight(node) {
example_gates.insert(
(op.op.name().to_string(), op.op.num_qubits()),
(op.op().name().to_string(), op.op().num_qubits()),
op.params_view().len(),
);
if op.op.control_flow() {
let blocks = op.op.blocks();
if op.op().control_flow() {
let blocks = op.op().blocks();
for block in blocks {
get_gates_num_params_circuit(&block, example_gates)?;
}
Expand All @@ -168,11 +166,11 @@ fn get_gates_num_params_circuit(
) -> PyResult<()> {
for inst in circuit.iter() {
example_gates.insert(
(inst.op.name().to_string(), inst.op.num_qubits()),
(inst.op().name().to_string(), inst.op().num_qubits()),
inst.params_view().len(),
);
if inst.op.control_flow() {
let blocks = inst.op.blocks();
if inst.op().control_flow() {
let blocks = inst.op().blocks();
for block in blocks {
get_gates_num_params_circuit(&block, example_gates)?;
}
Expand Down
Loading
Loading