Repository navigation
Conversation
The new example reuses the tutorial’s circuit and custom differentiator to fit a phase offset to a sine curve shifted by 0.2. It uses `tf.GradientTape` to differentiate the mean squared error with respect to the offset, then applies 30 gradient descent updates starting from zero. It prints the initial gradient, the loss before and after training, and the fitted offset. Refs tensorflow#488
|
Notebooks changed:
Review visual diffs and comment on any notebook cell. All comments sync back to this PR. Powered by ReviewNB |
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a new section to the gradients tutorial notebook demonstrating how to fit a sine curve using gradient descent with a custom differentiator. The feedback suggests optimizing performance by pre-converting the Cirq objects and inputs to TensorFlow tensors outside of the training loop to avoid repeated serialization overhead on every step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Readers can compute the gradient of a circuit expectation, but the tutorial ends before showing how to use that gradient to fit a parameter to data.
Summary of the fix
The new example reuses the tutorial’s circuit and custom differentiator to fit a phase offset to a sine curve shifted by 0.2. It uses
tf.GradientTapeto differentiate the mean squared error with respect to the offset, then applies 30 gradient descent updates starting from zero. It prints the initial gradient, the loss before and after training, and the fitted offset.Verification
repo_lintran twice, with no result shown for either run../scripts/format_check.shran, with no result shown../scripts/lint_all.shran, with no result shown. No test was run with the quantum change reverted, because no test was named as covering the reported bug, so none is shown to catch this bug.Closes #488