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

Move Option<Box<_>> into ExtraInstructionAttributes. #13127

Merged
merged 3 commits into from
Sep 12, 2024
Merged
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
4 changes: 2 additions & 2 deletions crates/accelerate/src/commutation_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ pub(crate) fn analyze_commutations_inner(
py,
&op1,
params1,
packed_inst0.extra_attrs.as_deref(),
&packed_inst0.extra_attrs,
qargs1,
cargs1,
&op2,
params2,
packed_inst1.extra_attrs.as_deref(),
&packed_inst1.extra_attrs,
qargs2,
cargs2,
MAX_NUM_QUBITS,
Expand Down
20 changes: 10 additions & 10 deletions crates/accelerate/src/commutation_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ impl CommutationChecker {
py,
&op1.instruction.operation.view(),
&op1.instruction.params,
op1.instruction.extra_attrs.as_deref(),
&op1.instruction.extra_attrs,
&qargs1,
&cargs1,
&op2.instruction.operation.view(),
&op2.instruction.params,
op2.instruction.extra_attrs.as_deref(),
&op2.instruction.extra_attrs,
&qargs2,
&cargs2,
max_num_qubits,
Expand Down Expand Up @@ -162,12 +162,12 @@ impl CommutationChecker {
py,
&op1.operation.view(),
&op1.params,
op1.extra_attrs.as_deref(),
&op1.extra_attrs,
&qargs1,
&cargs1,
&op2.operation.view(),
&op2.params,
op2.extra_attrs.as_deref(),
&op2.extra_attrs,
&qargs2,
&cargs2,
max_num_qubits,
Expand Down Expand Up @@ -232,12 +232,12 @@ impl CommutationChecker {
py: Python,
op1: &OperationRef,
params1: &[Param],
attrs1: Option<&ExtraInstructionAttributes>,
attrs1: &ExtraInstructionAttributes,
qargs1: &[Qubit],
cargs1: &[Clbit],
op2: &OperationRef,
params2: &[Param],
attrs2: Option<&ExtraInstructionAttributes>,
attrs2: &ExtraInstructionAttributes,
qargs2: &[Qubit],
cargs2: &[Clbit],
max_num_qubits: u32,
Expand Down Expand Up @@ -494,20 +494,20 @@ impl CommutationChecker {
fn commutation_precheck(
op1: &OperationRef,
params1: &[Param],
attrs1: Option<&ExtraInstructionAttributes>,
attrs1: &ExtraInstructionAttributes,
qargs1: &[Qubit],
cargs1: &[Clbit],
op2: &OperationRef,
params2: &[Param],
attrs2: Option<&ExtraInstructionAttributes>,
attrs2: &ExtraInstructionAttributes,
qargs2: &[Qubit],
cargs2: &[Clbit],
max_num_qubits: u32,
) -> Option<bool> {
if op1.control_flow()
|| op2.control_flow()
|| attrs1.is_some_and(|attr| attr.condition.is_some())
|| attrs2.is_some_and(|attr| attr.condition.is_some())
|| attrs1.condition().is_some()
|| attrs2.condition().is_some()
{
return Some(false);
}
Expand Down
17 changes: 7 additions & 10 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use std::cell::OnceCell;

use crate::bit_data::BitData;
use crate::circuit_instruction::{CircuitInstruction, OperationFromPython};
use crate::circuit_instruction::{
CircuitInstruction, ExtraInstructionAttributes, OperationFromPython,
};
use crate::imports::{ANNOTATED_OPERATION, CLBIT, QUANTUM_CIRCUIT, QUBIT};
use crate::interner::{Interned, Interner};
use crate::operations::{Operation, OperationRef, Param, StandardGate};
Expand Down Expand Up @@ -157,7 +159,7 @@ impl CircuitData {
qubits,
clbits,
params,
extra_attrs: None,
extra_attrs: ExtraInstructionAttributes::default(),
#[cfg(feature = "cache_pygates")]
py_op: OnceCell::new(),
});
Expand Down Expand Up @@ -209,7 +211,7 @@ impl CircuitData {
qubits,
clbits: no_clbit_index,
params,
extra_attrs: None,
extra_attrs: ExtraInstructionAttributes::default(),
#[cfg(feature = "cache_pygates")]
py_op: OnceCell::new(),
});
Expand Down Expand Up @@ -267,7 +269,7 @@ impl CircuitData {
qubits,
clbits: no_clbit_index,
params,
extra_attrs: None,
extra_attrs: ExtraInstructionAttributes::default(),
#[cfg(feature = "cache_pygates")]
py_op: OnceCell::new(),
});
Expand Down Expand Up @@ -626,12 +628,7 @@ impl CircuitData {
#[pyo3(signature = (func))]
pub fn map_nonstandard_ops(&mut self, py: Python<'_>, func: &Bound<PyAny>) -> PyResult<()> {
for inst in self.data.iter_mut() {
if inst.op.try_standard_gate().is_some()
&& !inst
.extra_attrs
.as_ref()
.is_some_and(|attrs| attrs.condition.is_some())
{
if inst.op.try_standard_gate().is_some() && inst.extra_attrs.condition().is_none() {
continue;
}
let py_op = func.call1((inst.unpack_py_op(py)?,))?;
Expand Down
Loading
Loading