Skip to content
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

Merged
merged 12 commits into from
Mar 31, 2020
Merged

Conversation

tonybruguier-google
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Mar 29, 2020

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")
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

@viathor viathor left a 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.

examples/direct_fidelity_estimation.py Show resolved Hide resolved
examples/direct_fidelity_estimation.py Outdated Show resolved Hide resolved
@tonybruguier-google
Copy link
Contributor Author

Thanks. I don't think I have permissions to merge so I'll wait for the bot :)

examples/direct_fidelity_estimation.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@viathor viathor left a 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.

examples/direct_fidelity_estimation.py Show resolved Hide resolved
examples/direct_fidelity_estimation.py Show resolved Hide resolved
@tonybruguier-google
Copy link
Contributor Author

Thanks. PTAL.

fidelity = 0.0

if samples_per_term == 0:
# sigma in https://arxiv.org/abs/1104.3835
assert type(sampler) == cirq.DensityMatrixSimulator
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this?

examples/direct_fidelity_estimation.py Show resolved Hide resolved
'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
Copy link
Collaborator

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tonybruguier-google
Copy link
Contributor Author

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.

Copy link
Collaborator

@viathor viathor left a 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')
Copy link
Collaborator

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.

Copy link
Contributor Author

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')
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@viathor viathor changed the title Refactor DFE to run samplers + add some experiment logging Refactor DFE to run samplers Mar 31, 2020
@tonybruguier-google
Copy link
Contributor Author

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.

@viathor viathor added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Mar 31, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Mar 31, 2020
@CirqBot CirqBot merged commit 1e50e4a into quantumlib:master Mar 31, 2020
@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 Mar 31, 2020
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.

None yet

5 participants