Skip to content

Conversation

@ddri
Copy link

@ddri ddri commented Jan 4, 2026

Fixes #1402

Summary

The "Adding Decoherence Noise" documentation example was missing a call to wrap_in_numshots_loop(1000) before executing the quantum program, causing the statistical calculations to be performed on only a single measurement instead of 1000.

Changes

  • Added noisy.wrap_in_numshots_loop(1000) before qc.run(noisy) in the decoherence noise example

Analysis

Without wrap_in_numshots_loop(), programs run with the default num_shots=1, producing a bitstrings array of shape (1, 2). The example then computes np.mean(bitstrings, axis=0) which averages over a single sample, making the statistics meaningless.

This fix matches the pattern used in all other examples in the same documentation file:

  • Example 1 (Amplitude damping): Line 375 uses wrap_in_numshots_loop(trials)
  • Example 2 (Dephased CZ): Line 536 uses wrap_in_numshots_loop(trials)
  • Readout noise examples: All use wrap_in_numshots_loop()

Note on T2 Parameter

The T2 parameter was left as T2=t1/2, which:

  • Matches the documented intent (line 670: "By default, T2 = T1 / 2")
  • Satisfies the physics constraint (T2 ≤ 2*T1)
  • Is more realistic than T2=2*t1 (which is the theoretical maximum)

The issue originally reported T2 as missing, but it was already added in a previous commit (likely during PR #1574 "Add doctests"), though the wrap_in_numshots_loop was still missing.

Testing

Verified that:

  • Default num_shots = 1 (confirmed in pyquil/quil.py:140)
  • All existing tests use wrap_in_numshots_loop() before qc.run() (see test/unit/test_quantum_computer.py)
  • All tests assert bitstrings.shape == (num_shots, num_qubits)

Fixes rigetti#1402

The "Adding Decoherence Noise" example was missing a call to
wrap_in_numshots_loop(1000) before executing the quantum program.
Without it, the program runs with only 1 shot (the default), making
the statistical calculations (np.mean over bitstrings) meaningless.

This fix adds the missing line, matching the pattern used in all
other examples in the same documentation file (amplitude damping,
dephased CZ, readout noise examples).

The T2 parameter is left as T2=t1/2, which:
- Matches the documented intent (line 670: "By default, T2 = T1 / 2")
- Satisfies the physics constraint (T2 <= 2*T1)
- Is more realistic than T2=2*t1 (theoretical maximum)
@ddri ddri requested a review from a team as a code owner January 4, 2026 21:10
Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Looks good to me 🤙

💡 To request another review, post a new comment with "/windsurf-review".

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.

Documentation: "Adding Decoherence Noise" Example Needs Changes to Work

1 participant