Skip to content

T1 decay for simulator #4326

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

Merged
merged 21 commits into from
Aug 6, 2021
Merged

T1 decay for simulator #4326

merged 21 commits into from
Aug 6, 2021

Conversation

asmuzsoy
Copy link
Contributor

When using a simulator, noise is applied after each gate. Previously, in the t1 decay method, there's only one wait gate, which means that noise is not properly applied "over time" when using a simulator. I've updated the method to add a number of wait gates proportional to the length of the delay when using a simulator.

Related to Issue #4264

As always, any feedback is appreciated!

@asmuzsoy asmuzsoy requested review from cduck, mrwojtek, vtomole and a team as code owners July 15, 2021 19:13
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 15, 2021
@@ -228,6 +202,39 @@ def test_curve_fit_plot_warning():
bad_fit.plot(include_fit=True)


@pytest.mark.parametrize('t1', [200, 500, 700])
def test_noise_model_constant(t1):
class GradualDecay(cirq.NoiseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think using cirq.NoiseModel.from_noise_model_like(cirq.amplitude_damp(...)) may provide a stronger demonstration here, since the new simulator-based experiment also works with duration-agnostic noise models.

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

I'm not really a huge fan of making the experiments require the user to provide a simulator=True/False flag that subtly changes how the experiment would be constructed in order to artificially simulate more noise.

I think the responsibility should fall on whoever made the simulator and accompanying noise model to take into consideration the increasing duration of the wait gate instead of artificially adding more waits to the experiment.

Can we leave the t1_decay code unchanged and still get the expected results on this test ? (maybe increasing the repetitions and tightening up the tolerance a bit too ?)

@95-martin-orion
Copy link
Collaborator

Can we leave the t1_decay code unchanged and still get the expected results on this test ?

Unfortunately, doing this right would require something along the lines of #2749, as our current noise models are agnostic to the duration of the gates involved. Making a model sensitive to WaitGate duration is easy enough, but it gets complicated when trying to make this work on a general level (how do you get the gate durations? is noise based on gate duration, or moment duration? etc.) which prompted this PR.

Essentially, the issue here is that some noise models (which may otherwise provide an accurate model of hardware) produce nonsense results here because the test assumes noise is continuous (rather than discretized). We'd like to be able to estimate T1 for these models, which requires discretizing the WaitGate.

Would changing the parameter name to something like discrete_noise be sufficient?

@MichaelBroughton
Copy link
Collaborator

MichaelBroughton commented Jul 19, 2021

Essentially, the issue here is that some noise models (which may otherwise provide an accurate model of hardware) produce nonsense results here because the test assumes noise is continuous (rather than discretized). We'd like to be able to estimate T1 for these models, which requires discretizing the WaitGate.

Why can't we just modify these existing noise models to check if the operation is a wait gate and then act accordingly ? Looking at the interfaces for cirq.NoiseModel it looks like it is definitely an option. Having a noise model do something different for for 10 wait gates after one another vs one longer wait gate that amounts to the same wait time seems like something we don't want our users to have to worry about and would be pretty confusing for them.

@95-martin-orion
Copy link
Collaborator

Why can't we just modify these existing noise models to check if the operation is a wait gate and then act accordingly ?

We can - but again, doing so correctly amounts to solving #2749. If a noise model can recognize that wait(20) and wait(40) take different amounts of time, I would also hope it knows that X(q0) and measure(q0) take different amounts of time - but exactly what those times should be and where to get them remain open design questions.

I think I understand your concern with this PR, though - it essentially "canonicalizes" the per-gate noise as a correct use case for this experiment, which is misleading. If we want to avoid that, I would support a version of this PR that only adds tests: test_noise_model_constant to demonstrate how to simulate the experiment, and a separate test to demonstrate that existing "discrete" noise models will misbehave. What do you think?

@MichaelBroughton
Copy link
Collaborator

Sure that makes a bit more sense to me.

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM with one last nit.

probs = data['true_count'] / (data['true_count'] + data['false_count'])

# Check that there is no decay in probability over time
assert np.all(np.isclose(np.mean(probs), probs, 0.2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 5, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Aug 6, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Aug 6, 2021

Automerge cancelled: A required status check is not present.

Missing statuses: ['Build docs', 'Build protos', 'Changed files test', 'Coverage check', 'Doc test', 'Format check', 'Lint check', 'Misc check', 'Notebook formatting', 'Pytest MacOS (3.7)', 'Pytest MacOS (3.8)', 'Pytest MacOS (3.9)', 'Pytest Ubuntu (3.7)', 'Pytest Ubuntu (3.8)', 'Pytest Ubuntu (3.9)', 'Pytest Windows (3.7)', 'Pytest Windows (3.8)', 'Pytest Windows (3.9)', 'Type check', 'Typescript lint check', 'Typescript tests', 'Typescript tests coverage']

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Aug 6, 2021
@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 6, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Aug 6, 2021
@CirqBot CirqBot merged commit c3f9a5d into quantumlib:master Aug 6, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Aug 6, 2021
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
When using a simulator, noise is applied after each gate. Previously, in the t1 decay method, there's only one wait gate, which means that noise is not properly applied "over time" when using a simulator. I've updated the method to add a number of wait gates proportional to the length of the delay when using a simulator.

Related to Issue #[4264](quantumlib#4264)

As always, any feedback is appreciated!
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
When using a simulator, noise is applied after each gate. Previously, in the t1 decay method, there's only one wait gate, which means that noise is not properly applied "over time" when using a simulator. I've updated the method to add a number of wait gates proportional to the length of the delay when using a simulator.

Related to Issue #[4264](quantumlib#4264)

As always, any feedback is appreciated!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants