Skip to content

Add GPU simulator tests#2950

Closed
orpuente-MS wants to merge 14 commits intomainfrom
oscarpuente/add-gpu-tests
Closed

Add GPU simulator tests#2950
orpuente-MS wants to merge 14 commits intomainfrom
oscarpuente/add-gpu-tests

Conversation

@orpuente-MS
Copy link
Copy Markdown
Contributor

@orpuente-MS orpuente-MS commented Feb 13, 2026

This PR extends the work in #2905 by adding tests for the GPU simulator. It also unifies the tests for all simulators in this test-suite, which serves as a mechanism to verify that they all behave the same.

@orpuente-MS orpuente-MS marked this pull request as ready for review February 17, 2026 18:33
Comment thread source/pip/src/qir_simulation/tests/noiseless_tests.rs
}
}

#[ignore = "loss behavior in cpu and gpu simulators is different"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan with the ignore? Is this meant to stay here indefinitely or is this test going to be updated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a branch fixing this difference in loss behavior. But I was waiting for this PR to merge so that I could test the changes on that branch.

/// ```
macro_rules! check_programs_are_eq {
// Pattern without num_results - defaults to 0
// Multi-simulator entry: runs the same test on each listed simulator
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I'm just not seeing the benefit of using macros so extensively. I find the syntax so difficult to follow and debug. If I'm the only one that feels this way about macros, I'm happy to be wrong - but I'd be surprised any of us would be able to read this easily without consulting documentation.

Copilot suggested something like the following to support dispatching based on simulator type. It's shorter and more readable... why go for something more complex?

pub enum Sim {
    Noiseless,
    Noisy,
    Stabilizer,
    Gpu,
}

pub fn check_programs_are_eq(
    simulators: &[Sim],
    programs: &[Vec<QirInstruction>],
    num_qubits: u32,
    num_results: u32,
) {
    use qdk_simulators::cpu_full_state_simulator::{NoiselessSimulator, NoisySimulator};
    use qdk_simulators::stabilizer_simulator::StabilizerSimulator;

    for sim in simulators {
        match sim {
            Sim::Noiseless => {
                check_programs_are_eq_cpu::<NoiselessSimulator>(programs, num_qubits, num_results);
            }
            Sim::Noisy => {
                check_programs_are_eq_cpu::<NoisySimulator>(programs, num_qubits, num_results);
            }
            Sim::Stabilizer => {
                check_programs_are_eq_cpu::<StabilizerSimulator>(programs, num_qubits, num_results);
            }
            Sim::Gpu => {
                if gpu_is_available() {
                    check_programs_are_eq_gpu(programs, num_qubits, num_results);
                } else {
                    eprintln!("Skipping GPU test: no compatible GPU adapter found");
                }
            }
        }
    }
}

@@ -732,6 +993,49 @@ where
/// }
/// ```
macro_rules! check_basis_table {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about the macros... wouldn't this be more readable as a normal function? (Taking advantage of the same simulator type enum from the other comment)

pub fn check_basis_table(
    simulators: &[Sim],
    num_qubits: u32,
    table: &[(Vec<QirInstruction>, u32, u32)],
) {
...
}

@minestarks
Copy link
Copy Markdown
Member

@orpuente-MS I get a ton of error messages running these tests locally, but no failing tests. What gives?

This is on my Windows devbox VM

running 94 tests
test displayable_output::tests::display_rounds_to_neg_zero ... ok
test displayable_output::tests::display_neg_zero ... ok
test generic_estimator::tests::test_ordered_bfs ... ok
test displayable_output::tests::display_preserves_order ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_lowercase_pauli_errors ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_invalid_pauli_char_errors ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_inconsistent_pauli_length_errors ... ok
test qir_simulation::correlated_noise::tests::noise_table_scientific_notation ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_single_more_than_two_cols_errors ... ok
test qir_simulation::correlated_noise::tests::simple_noise_with_header ... ok
test qir_simulation::correlated_noise::tests::simple_noise_table ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_invalid_probability_errors ... ok
test qir_simulation::correlated_noise::tests::noise_table_with_whitespaces ... ok
test qir_simulation::correlated_noise::tests::noise_table_with_comments ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_invalid_float_errors ... ok
test qir_simulation::correlated_noise::tests::noise_table_with_newlines ... ok
test qir_simulation::correlated_noise::tests::csv_row_with_single_col_errors ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noiseless_tests::cz_symmetric ... ok
test qir_simulation::tests::noiseless_tests::h_gate_creates_superposition ... ok
test qir_simulation::tests::noiseless_tests::h_is_self_adjoint ... ok
test qir_simulation::tests::noiseless_tests::rxx_zero_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::rxx_pi_eq_x_tensor_x ... ok
test qir_simulation::tests::noiseless_tests::rz_zero_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::ry_pi_eq_y ... ok
test qir_simulation::tests::noiseless_tests::ryy_zero_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::rx_neg_half_pi_eq_sx_adj ... ok
test qir_simulation::tests::noiseless_tests::rx_zero_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::mz_does_not_reset ... ok
test qir_simulation::tests::noiseless_tests::ry_two_pi_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::rz_pi_eq_z ... ok
test qir_simulation::tests::noiseless_tests::reset_takes_qubit_back_to_zero ... ok
test qir_simulation::tests::noiseless_tests::rz_quarter_pi_eq_t ... ok
test qir_simulation::tests::noiseless_tests::mov_is_noop_without_noise ... ok
test qir_simulation::tests::noiseless_tests::rx_two_pi_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::rx_pi_eq_x ... ok
test qir_simulation::tests::noiseless_tests::rz_two_pi_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::s_adj_squared_eq_z ... ok
test qir_simulation::tests::noiseless_tests::s_and_s_adj_cancel ... ok
test qir_simulation::tests::noiseless_tests::rz_neg_quarter_pi_eq_t_adj ... ok
test qir_simulation::tests::noiseless_tests::rx_half_pi_eq_sx ... ok
test qir_simulation::tests::noiseless_tests::ryy_pi_eq_y_tensor_y ... ok
test qir_simulation::tests::noiseless_tests::ry_zero_eq_identity ... ok
test qir_simulation::tests::noisy_tests::bell_state_with_combined_noise ... ignored, loss behavior in cpu and gpu simulators is different
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noiseless_tests::rz_half_pi_eq_s ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noiseless_tests::ghz_state_three_qubits ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noiseless_tests::mresetz_resets_after_measurement ... ok
test qir_simulation::tests::noiseless_tests::rz_neg_half_pi_eq_s_adj ... ok
test qir_simulation::tests::noiseless_tests::bell_state_produces_correlated_measurements ... ok
test qir_simulation::tests::noiseless_tests::s_squared_eq_z ... ok
test qir_simulation::tests::noiseless_tests::rzz_pi_eq_z_tensor_z ... ok
test qir_simulation::tests::noiseless_tests::sx_and_sx_adj_cancel ... ok
test qir_simulation::tests::noiseless_tests::sx_adj_squared_eq_x ... ok
test qir_simulation::tests::noiseless_tests::swap_exchanges_qubit_states ... ok
test qir_simulation::tests::noiseless_tests::z_eq_h_x_h ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noiseless_tests::swap_twice_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::y_is_self_adjoint ... ok
test qir_simulation::tests::noiseless_tests::two_qubit_gate_truth_tables ... ok
test qir_simulation::tests::noiseless_tests::y_gate_eq_x_z_and_z_x ... ok
test qir_simulation::tests::noisy_tests::two_qubit_loss ... ignored, loss behavior in cpu and gpu simulators is different
test qir_simulation::tests::noiseless_tests::swap_commutes_operands ... ok
test qir_simulation::tests::noiseless_tests::x_is_self_adjoint ... ok
test qir_simulation::tests::noiseless_tests::t_and_t_adj_cancel ... ok
test qir_simulation::tests::noisy_tests::loss_noise_produces_loss_marker ... ok
test qir_simulation::tests::noiseless_tests::sx_squared_eq_x ... ok
test qir_simulation::tests::noiseless_tests::t_fourth_eq_z ... ok
test qir_simulation::tests::noiseless_tests::t_adj_fourth_eq_z ... ok
test qir_simulation::tests::noiseless_tests::x_eq_h_z_h ... ok
test qir_simulation::tests::noiseless_tests::z_is_self_adjoint ... ok
test qir_simulation::tests::noisy_tests::cx_xx_noise_flips_both_qubits ... ok
test qir_simulation::tests::noisy_tests::cx_xi_noise_flips_control_qubit ... ok
test qir_simulation::tests::noisy_tests::different_gates_have_different_noise ... ok
test qir_simulation::tests::noisy_tests::cx_ix_noise_flips_target_qubit ... ok
test qir_simulation::tests::noiseless_tests::rzz_zero_eq_identity ... ok
test qir_simulation::tests::noiseless_tests::single_qubit_gate_truth_tables ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noisy_tests::z_noise_does_not_affect_computational_basis ... ok
test qir_simulation::tests::noisy_tests::z_noise_on_superposition_affects_interference ... ok
test qir_simulation::tests::noisy_tests::x_noise_on_x_gate_causes_bit_flips ... ok
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
test qir_simulation::tests::noisy_tests::rz_gate_with_z_noise_no_effect_on_basis ... ok
test qir_simulation::tests::noisy_tests::rx_gate_with_noise ... ok
test qir_simulation::tests::noisy_tests::simulator_completes_all_shots ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_three_qubit_correlated ... ok
test qir_simulation::tests::noisy_tests::swap_noise_affects_swapped_qubits ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_two_qubit_independent_noise ... ok
test qir_simulation::tests::noisy_tests::noiseless_config_produces_clean_results ... ok
test qir_simulation::tests::noisy_tests::rxx_gate_with_noise ... ok
test qir_simulation::tests::noisy_tests::x_noise_on_h_gate_does_not_affect_outcome ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_single_qubit_z_noise_no_effect ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_two_qubit_correlated_xx_noise ... ok
test qir_simulation::tests::noisy_tests::cz_noise_affects_outcome ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_single_qubit_x_noise ... ok
test qir_simulation::tests::noiseless_tests::simulator_completes_all_shots ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_combined_with_gate_noise ... ok
test qir_simulation::tests::noisy_tests::noise_accumulates_across_multiple_gates ... ok
test qir_simulation::tests::noisy_tests::noise_intrinsic_multiple_ids ... ok

@orpuente-MS
Copy link
Copy Markdown
Contributor Author

Closing this PR in favor of #3124.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants