-
Notifications
You must be signed in to change notification settings - Fork 984
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
Refactor DFE to run samplers #2870
Conversation
|
||
Returns: | ||
The estimated fidelity. | ||
""" | ||
# n_trials is upper-case N in https://arxiv.org/abs/1104.3835 | ||
|
||
if log_output_filename: | ||
sys.stdout = open(log_output_filename, "w") |
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.
This breaks the principle of separation of concerns. Function for direct fidelity estimation should not be responsible for setting up logging.
Perhaps we don't really need to print anything in this function. It seems that what we print are the inputs and return value anyway.
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.
I had a concern that it might not be the right way. I reverted the changes to the logging, and instead narrowed the scope to only the refactoring and I will address the logging later?
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.
Two minor changes left. Please address them before merging.
Thanks. I don't think I have permissions to merge so I'll wait for the bot :) |
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.
Sorry, came back to merge this for you, but instead found an issue that should be fixed first.
Thanks. PTAL. |
fidelity = 0.0 | ||
|
||
if samples_per_term == 0: | ||
# sigma in https://arxiv.org/abs/1104.3835 | ||
assert type(sampler) == cirq.DensityMatrixSimulator |
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.
Please raise an exception instead of asserting.
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.
Like this?
'noise' parameter above and instead run an estimation of the | ||
characteristic function. | ||
|
||
samples_per_term: is set to 0, we use the 'sampler' parameter above as |
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.
nit: replace "is set to 0" with "if set to 0"
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.
Done.
Sorry about this. I think I hadn't pushed on time. I checked that the changes are in. Thank you for the careful review. PTAL, no hurry. |
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.
Much better, thanks! You also need to add a unit test to placate the test coverage check.
fidelity = 0.0 | ||
|
||
if samples_per_term == 0: | ||
# sigma in https://arxiv.org/abs/1104.3835 | ||
if not isinstance(sampler, cirq.DensityMatrixSimulator): | ||
raise TypeError('sampler is not a cirq.DensityMatrixSimulator') |
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.
nit: maybe add "..., but samples_per_term is zero" to guide the user towards the correct parameters.
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.
Done.
fidelity = 0.0 | ||
|
||
if samples_per_term == 0: | ||
# sigma in https://arxiv.org/abs/1104.3835 | ||
if not isinstance(sampler, cirq.DensityMatrixSimulator): | ||
raise TypeError('sampler is not a cirq.DensityMatrixSimulator') |
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.
Test coverage failed. You need a unit test that verifies the exception is raised in the right circumstances.
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.
Done.
Sorry for the double-push. My first one failed the check, so I was waiting to comment but now I can because the second push passed. PTAL. |
No description provided.