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

Extra flush for rotations by PI #201

Merged
merged 2 commits into from
Jul 8, 2024
Merged
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
27 changes: 27 additions & 0 deletions sparsesim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ impl QuantumSim {
} else {
self.mcx(ctls, target);
}
self.flush_ops();
// Rx/Ry are different from X/Y by a global phase of -i, so apply that here when indicated by m01,
// for mathematical correctness.
let (_, ctls) = self.resolve_and_check_qubits(target, ctls);
Expand Down Expand Up @@ -1507,6 +1508,32 @@ mod tests {
assert!(sim.joint_probability(&[q]).is_nearly_zero());
}

/// Verifies that an Rx rotation by PI, which becomes an X gate, is correctly flushed.
#[test]
fn test_rx_pi_flushed() {
let mut sim = QuantumSim::new(None);
let q = sim.allocate();
sim.rx(PI, q);
assert!(almost_equal(
sim.joint_probability(&[q]),
sim.joint_probability(&[q])
));
assert!(!sim.joint_probability(&[q]).is_nearly_zero());
}

/// Verifies that an Ry rotation by PI, which becomes an Y gate, is correctly flushed.
#[test]
fn test_ry_pi_flushed() {
let mut sim = QuantumSim::new(None);
let q = sim.allocate();
sim.ry(PI, q);
assert!(almost_equal(
sim.joint_probability(&[q]),
sim.joint_probability(&[q])
));
assert!(!sim.joint_probability(&[q]).is_nearly_zero());
}

/// Utility for testing operation equivalence.
fn assert_operation_equal_referenced<F1, F2>(mut op: F1, mut reference: F2, count: usize)
where
Expand Down