Skip to content

Commit

Permalink
removing code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderivrii committed Feb 10, 2025
1 parent 68e6a7f commit 8ccb8da
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions crates/accelerate/src/remove_identity_equiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ fn remove_identity_equiv(
// Skip parameterized gates
continue;
}
match inst.op.view() {
let view = inst.op.view();
match view {
OperationRef::StandardGate(gate) => {
let (dim, trace) = match gate {
StandardGate::RXGate | StandardGate::RYGate | StandardGate::RZGate => {
Expand Down Expand Up @@ -120,8 +121,10 @@ fn remove_identity_equiv(
global_phase_update += (trace / dim).arg();
}
}
OperationRef::Gate(gate) => {
if let Some(matrix) = gate.matrix(inst.params_view()) {
_ => {
let matrix = view.matrix(inst.params_view());
// If view.matrix() returns None, then there is no matrix and we skip the operation.
if let Some(matrix) = matrix {
let error = get_error_cutoff(inst);
let dim = matrix.shape()[0] as f64;
let trace: Complex64 = matrix.diag().iter().sum();
Expand All @@ -133,20 +136,6 @@ fn remove_identity_equiv(
}
}
}
OperationRef::Unitary(gate) => {
if let Some(matrix) = gate.matrix(inst.params_view()) {
let error = get_error_cutoff(inst);
let dim = matrix.shape()[0] as f64;
let trace: Complex64 = matrix.diag().iter().sum();
let f_pro = (trace / dim).abs().powi(2);
let gate_fidelity = (dim * f_pro + 1.) / (dim + 1.);
if (1. - gate_fidelity).abs() < error {
remove_list.push(op_node);
global_phase_update += (trace / dim).arg();
}
}
}
_ => continue,
}
}
for node in remove_list {
Expand Down

0 comments on commit 8ccb8da

Please sign in to comment.