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

Add classes to aid in providing simulated versions of devices #4747

Merged
merged 10 commits into from
Dec 28, 2021

Conversation

dstrain115
Copy link
Collaborator

  • Add a validator that checks (some of) the common errors occuring
    when sending circuits to quantum engine. This likely needs more
    checks, but these can be added over time to match engine behavior.
  • Adds convenience functions to create SimulatedLocalEngine instances
    from a device or from a device specification proto.
  • Adds proto device specifications for example Sycamore devices that
    can be loaded without API access.

- Add a validator that checks (some of) the common errors occuring
when sending circuits to quantum engine.  This likely needs more
checks, but these can be added over time to match engine behavior.
- Adds convenience functions to create SimulatedLocalEngine instances
from a device or from a device specification proto.
- Adds proto device specifications for example Sycamore devices that
can be loaded without API access.
@dstrain115 dstrain115 requested review from cduck, vtomole, wcourtney and a team as code owners December 13, 2021 18:53
@dstrain115 dstrain115 requested a review from viathor December 13, 2021 18:53
@CirqBot CirqBot added the size: XL lines changed >1000 label Dec 13, 2021
@MichaelBroughton MichaelBroughton self-assigned this Dec 13, 2021
max_repetitions: int = MAX_TOTAL_REPETITIONS,
max_duration_ns: int = 55000,
) -> VALIDATOR_TYPE:
"""Creates a Callanle gate set validator with a set message size."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

callable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

max_duration_ns: int = 55000,
) -> VALIDATOR_TYPE:
"""Creates a Callanle gate set validator with a set message size."""
return lambda c, s, r: validate_for_engine(
Copy link
Collaborator

Choose a reason for hiding this comment

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

might want to double check the style guide, but I think the preferred style is to use an inline function definition rather than a variable here

def create_validator(...):
  def _validator(c, s, r):
      return
  return _validator

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this looks and reads a lot better. Changed.

gate_set: Serializer,
max_size: int = MAX_MESSAGE_SIZE,
) -> None:
"""Validate that the message size is below the maximum size limit."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

document args here and other public functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return create_noiseless_virtual_engine_from_proto(processor_ids, specifications, gate_sets)


def create_noiseless_virtual_engine_from_latest_templates():
Copy link
Collaborator

Choose a reason for hiding this comment

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

return type annotation here and elsewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator Author

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Thanks for the review!

max_repetitions: int = MAX_TOTAL_REPETITIONS,
max_duration_ns: int = 55000,
) -> VALIDATOR_TYPE:
"""Creates a Callanle gate set validator with a set message size."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

max_duration_ns: int = 55000,
) -> VALIDATOR_TYPE:
"""Creates a Callanle gate set validator with a set message size."""
return lambda c, s, r: validate_for_engine(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this looks and reads a lot better. Changed.

return create_noiseless_virtual_engine_from_proto(processor_ids, specifications, gate_sets)


def create_noiseless_virtual_engine_from_latest_templates():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

gate_set: Serializer,
max_size: int = MAX_MESSAGE_SIZE,
) -> None:
"""Validate that the message size is below the maximum size limit."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

some questionable unused arguments

raise RuntimeError('Code must measure at least one qubit.')


def validate_gate_set(
Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @tanujkhattar @MichaelBroughton will this function be replaced once devices api and gatesets have fully landed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may need to be modified, but I don't think it will go away. We will still need to validate that the circuit has the correct gates.

Args:
max_size: proto size limit to check against.

Returns: Callable to use in validation with the max_size already set.
Copy link
Collaborator

Choose a reason for hiding this comment

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

max_size isn't used here. unless I'm missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, I forgot to add it to the generator function, even though that was the whole point. Also added a test to verify.

repetitions: Union[int, List[int]],
max_moments: int = MAX_MOMENTS,
max_repetitions: int = MAX_TOTAL_REPETITIONS,
max_duration_ns: int = 55000,
Copy link
Collaborator

Choose a reason for hiding this comment

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

max_duration_ns unused?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.
This was for testing the max duration of the circuit, but I need to go back and modify the way the durations are stored first. I'll add it back in a follow-up PR.

max_repetitions: int = MAX_TOTAL_REPETITIONS,
max_duration_ns: int = 55000,
) -> VALIDATOR_TYPE:
"""Creates a Callanle gate set validator with a set message size.
Copy link
Collaborator

Choose a reason for hiding this comment

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

callanle -> callable

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a matter of style, but I would find it enormously helpful if these factory functions gave some hint at where you could pass the result to:

"""Creates a validator...

This can be a useful helper for generating validators for cg.ValidatingSampler's validator argument
"""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. Done. Let me know if the additional paragraph is still not clear.

@dstrain115 dstrain115 merged commit 58f6a6f into quantumlib:master Dec 28, 2021
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
…mlib#4747)

Add classes to aid in providing simulated versions of devices

- Add a validator that checks (some of) the common errors occurring
when sending circuits to quantum engine.  This likely needs more
checks, but these can be added over time to match engine behavior.
- Adds convenience functions to create SimulatedLocalEngine instances
from a device or from a device specification proto.
- Adds proto device specifications for example Sycamore devices that
can be loaded without API access.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…mlib#4747)

Add classes to aid in providing simulated versions of devices

- Add a validator that checks (some of) the common errors occurring
when sending circuits to quantum engine.  This likely needs more
checks, but these can be added over time to match engine behavior.
- Adds convenience functions to create SimulatedLocalEngine instances
from a device or from a device specification proto.
- Adds proto device specifications for example Sycamore devices that
can be loaded without API access.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants