-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add classes to aid in providing simulated versions of devices #4747
Conversation
- 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.
max_repetitions: int = MAX_TOTAL_REPETITIONS, | ||
max_duration_ns: int = 55000, | ||
) -> VALIDATOR_TYPE: | ||
"""Creates a Callanle gate set validator with a set message size.""" |
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.
callable?
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.
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( |
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.
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
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.
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.""" |
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.
document args here and other public functions
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.
return create_noiseless_virtual_engine_from_proto(processor_ids, specifications, gate_sets) | ||
|
||
|
||
def create_noiseless_virtual_engine_from_latest_templates(): |
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.
return type annotation here and elsewhere
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.
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.
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.""" |
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.
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( |
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.
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(): |
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.
gate_set: Serializer, | ||
max_size: int = MAX_MESSAGE_SIZE, | ||
) -> None: | ||
"""Validate that the message size is below the maximum size limit.""" |
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.
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.
some questionable unused arguments
raise RuntimeError('Code must measure at least one qubit.') | ||
|
||
|
||
def validate_gate_set( |
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.
cc @tanujkhattar @MichaelBroughton will this function be replaced once devices api and gatesets have fully landed?
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.
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. |
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.
max_size
isn't used here. unless I'm missing something?
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.
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, |
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.
max_duration_ns
unused?
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.
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. |
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.
callanle -> callable
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 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
"""
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.
Good idea. Done. Let me know if the additional paragraph is still not clear.
…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.
…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.
when sending circuits to quantum engine. This likely needs more
checks, but these can be added over time to match engine behavior.
from a device or from a device specification proto.
can be loaded without API access.