Repository navigation
Support multiple logical observables and error decomposition in qec_memory decoding #501
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
mhucka marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add an assertion with
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the 13-item |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,9 +80,119 @@ def test_get_logical_error_probability(): | |
| "repetition_code:memory", rounds=5, distance=3 | ||
| ) | ||
| circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit) | ||
| for error_rate, expected_lep in zip([0.0, 0.01, 0.1, 0.5], [0.0, 0.0, 0.0, 0.7]): | ||
| for error_rate, expected_lep_false, expected_lep_true in zip( | ||
| [0.0, 0.01, 0.1, 0.5], | ||
| [0.0, 0.0, 0.0, 0.7], | ||
| [0.0, 0.0, 0.0, 0.6], | ||
| ): | ||
| data = _generate_fake_qec_data(keys, error_rate, shots, rng) | ||
| assert ( | ||
| qec_decoding.get_logical_error_probability(data, circuit, 0.001) | ||
| == expected_lep | ||
| == expected_lep_false | ||
| ) | ||
| assert ( | ||
| qec_decoding.get_logical_error_probability( | ||
| data, circuit, 0.001, decompose_errors=False | ||
| ) | ||
| == expected_lep_false | ||
| ) | ||
| assert ( | ||
| qec_decoding.get_logical_error_probability( | ||
| data, circuit, 0.001, decompose_errors=True | ||
| ) | ||
| == expected_lep_true | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not hasattr(cirq.transformers, "apply_lazy_args_on_circuit_operation"), | ||
| reason="Requires pre-release version of Cirq", | ||
| ) | ||
| def test_get_logical_error_probability_no_observables(): | ||
| rng = np.random.default_rng(0) | ||
| keys = [ | ||
| "0", | ||
| "1", | ||
| "2[0]", | ||
| "2[1]", | ||
| "2[2]", | ||
| "2[3]", | ||
| "3[0]", | ||
| "3[1]", | ||
| "3[2]", | ||
| "3[3]", | ||
| "10", | ||
| "11", | ||
| "12", | ||
| ] | ||
| shots = 10 | ||
| stim_circuit = stim.Circuit.generated( | ||
| "repetition_code:memory", rounds=5, distance=3 | ||
| ) | ||
| stim_circuit_no_obs = stim.Circuit() | ||
| for inst in stim_circuit: | ||
| if inst.name != "OBSERVABLE_INCLUDE": | ||
| stim_circuit_no_obs.append(inst) | ||
| circuit_no_obs = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit_no_obs) | ||
| data = _generate_fake_qec_data(keys, 0.1, shots, rng) | ||
|
|
||
| hardware_stim_circuit = qec_decoding.cirq_to_stim_hardware_circuit(circuit_no_obs) | ||
| _, obs_arr = qec_decoding.extract_detection_events(data, hardware_stim_circuit) | ||
| assert obs_arr.shape == (shots, 0) | ||
|
|
||
| with pytest.raises(ValueError, match="at least one observable"): | ||
| qec_decoding.get_logical_error_probability(data, circuit_no_obs, 0.001) | ||
| with pytest.raises(ValueError, match="at least one observable"): | ||
| qec_decoding.get_logical_error_probability( | ||
| data, circuit_no_obs, 0.001, per_observable=True | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not hasattr(cirq.transformers, "apply_lazy_args_on_circuit_operation"), | ||
| reason="Requires pre-release version of Cirq", | ||
| ) | ||
| def test_get_logical_error_probability_multi_observable(): | ||
| rng = np.random.default_rng(0) | ||
| keys = [ | ||
| "0", | ||
| "1", | ||
| "2[0]", | ||
| "2[1]", | ||
| "2[2]", | ||
| "2[3]", | ||
| "3[0]", | ||
| "3[1]", | ||
| "3[2]", | ||
| "3[3]", | ||
| "10", | ||
| "11", | ||
| "12", | ||
| ] | ||
| shots = 10 | ||
| stim_circuit = stim.Circuit.generated( | ||
| "repetition_code:memory", rounds=5, distance=3 | ||
| ) | ||
| stim_circuit.append("OBSERVABLE_INCLUDE", [stim.target_rec(-2)], 1) | ||
| circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit) | ||
|
|
||
| data_noiseless = _generate_fake_qec_data(keys, 0.0, shots, rng) | ||
| assert ( | ||
| qec_decoding.get_logical_error_probability(data_noiseless, circuit, 0.001) | ||
| == 0.0 | ||
| ) | ||
| np.testing.assert_array_equal( | ||
| qec_decoding.get_logical_error_probability( | ||
| data_noiseless, circuit, 0.001, per_observable=True | ||
| ), | ||
| np.array([0.0, 0.0]), | ||
| ) | ||
|
|
||
| data_noisy = _generate_fake_qec_data(keys, 0.5, shots, rng) | ||
| joint_lep = qec_decoding.get_logical_error_probability(data_noisy, circuit, 0.001) | ||
| per_obs_lep = qec_decoding.get_logical_error_probability( | ||
| data_noisy, circuit, 0.001, per_observable=True | ||
| ) | ||
| assert isinstance(joint_lep, float) | ||
| assert per_obs_lep.shape == (2,) | ||
| assert np.max(per_obs_lep) <= joint_lep <= np.sum(per_obs_lep) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this last test succeed for any Boolean matrix? If so, it would pass even if something went wrong with the preceding calculations. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful to add an explanation of why this matters, and what values to use in what circumstances. Something that brings up the fact that PyMatching ignores error mechanisms with more than two detection events unless they are decomposed, so
Truewould be appropriate for surface codes.