-
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
Replace AbstractEngineProcessorShim #4842
Conversation
I don't think we can use |
related: #2820 |
@MichaelBroughton @dstrain115 this should be ready for your review, PTAL |
def get_processor(self) -> 'cg.EngineProcessor': | ||
"""Return a `cg.EngineProcessor` for the specified processor_id.""" | ||
engine = cg.get_engine() | ||
return cg.EngineProcessor( |
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.
Why not just engine.get_processor(self.processor_id)?
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.
ah. (1) I didn't think to do that; (2) I thought I was going to have to put in more environment variable magic into this function that turned out not to be necessary.
changed as suggested.
This implementation hardcodes the `cg.SQRT_ISWAP_GATESET` to construct | ||
the sampler until this argument is made optional. | ||
""" | ||
return self.get_processor().get_sampler(cg.SQRT_ISWAP_GATESET) |
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.
Should the default be the CircuitSerializer? It's more general and can handle the union of the other gatesets (at the cost of being less tested, but please use this to help test it!)
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.
oh wow. when was that merged in? will test it out
Only 'rainbow' and 'weber' are recognized processor_ids and the device information | ||
may not be up-to-date, as it is completely local. | ||
""" | ||
return _DEVICES_BY_ID[self.processor_id] |
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.
Do you want to use the devices in devices/specifications?
For instance, there is this call which is very similar:
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.
yes I do.
I'm going to try to see what I have to add to that module so I can request the latest template by name instead of getting them in a list.
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 think I'd need something like #4909 to re-use as much as possible
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.
merged in #4909 to use virtual_engine_factory stuff to make these local devices
Also, did #4850 solve your optional gate set issues? Or is there further work needed? |
from cirq._compat import dataclass_repr | ||
from cirq_google.engine.virtual_engine_factory import ( | ||
MOST_RECENT_TEMPLATES, | ||
_create_device_spec_from_template, |
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.
Should this function not have a _
prefix if it's imported here?
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.
hmm I think since it's all inside cirq_google
it's fine.
Do you think it should be a public method? Easier to make public later than vice versa
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.
My impression is that _
implies it's private within a module, but I'm not a Python guru so not a strong preference :) According to The naming guide from "PEP 8 -- Style Guide for Python Code":
"_single_leading_underscore
: weak "internal use" indicator. E.g. from M import * does not import objects whose names start with an underscore."
This seems to imply that objects used outside a module shouldn't have an underscore.
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.
that still depends on your interpretation of the meaning of "internal", right? module internal or package internal. As an example, we have cirq._compat
that's used throughout cirq but external users should not import.
In any event, if folks (i.e. you) think this is a valuable method for users to use, we can make it "public"
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.
OK sounds good, no strong preference from me on whether to have _
. As for whether we should make it available for users to use, I'd say not until there's a specific need. So keeping the underscore sgtm.
engine = cg.get_engine() | ||
return engine.get_processor(self.processor_id) | ||
|
||
def get_sampler(self) -> 'cg.QuantumEngineSampler': |
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.
Does this need to be reimplemented if the abstract class logic is the same?
Is the more specific cg.QuantumEngineSampler
type used anywhere over the cirq.Sampler
?
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 catch. this was vestigial from when I had to hack in a gateset
"""Return a `cg.QuantumEngineSampler` for the specified processor_id.""" | ||
return self.get_processor().get_sampler() | ||
|
||
def get_device(self) -> 'cirq.Device': |
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.
ditto
- Factor out `create_noiseless_virtual_processor_from_proto` for use in `create_noiseless_virtual_engine_from_proto` - Factor out `_create_device_spec_from_template` for use in `create_noiseless_virtual_processor_from_template` and `create_noiseless_virtual_engine_from_templates` - Factor out `MOST_RECENT_TEMPLATES` for use in `create_noiseless_virtual_engine_from_latest_templates` and (manually) in `create_noiseless_virtual_processor_from_template` This unblocks creating one processor at a time for use in #4842
@verult @dstrain115 ptal. With #4909 merged in, the diff should be fixed (smaller) |
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.
Did a surface-level review and lgtm. Please feel free to ignore nits.
def _json_dict_(self): | ||
return cirq.dataclass_json_dict(self) | ||
|
||
def descriptive_name(self) -> str: |
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: Should this be __str__()
?
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
}, | ||
clear=True, | ||
): | ||
proc_rec = cg.EngineProcessorRecord('rainbow') |
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: declare processor ID as a constant at top of file. Makes it easier to change when we remove device templates in the future.
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.
gonna definitely keep it 1) to keep the tests descriptive and readable 2) to make sure we don't remove device templates in the future!
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.
Approving per discussion in chat
- Factor out `create_noiseless_virtual_processor_from_proto` for use in `create_noiseless_virtual_engine_from_proto` - Factor out `_create_device_spec_from_template` for use in `create_noiseless_virtual_processor_from_template` and `create_noiseless_virtual_engine_from_templates` - Factor out `MOST_RECENT_TEMPLATES` for use in `create_noiseless_virtual_engine_from_latest_templates` and (manually) in `create_noiseless_virtual_processor_from_template` This unblocks creating one processor at a time for use in quantumlib#4842
We were using `AbstractEngineProcessorShim` pending quantumlib#4644 and friends. Those PRs have landed. For data hygiene as part of the workflow tools, we need to record what processor was used. This PR introduces an abstract `ProcessorRecord` interface and three implementations for mapping (processor_id, whether it's a simulator, what sort of noise) tuples to an AbstractProcessor instance for doing the work. - Remove `AbstractEngineProcessorShim` - Add dataclasses for data hygene - Now we can have proper serialization tests for anything that saves a `QuantumRuntimeConfiguration`, hence the new json files - We don't need to shim over `cirq.read_json` in tests that make use of `AbstractEngineProcessorShim` any more - Side effect: the new engine-processor-backed instances mean we have to use "real" qubits in the tests, so there are some knock-on test changes. cc @dstrain115 @MichaelBroughton
- Factor out `create_noiseless_virtual_processor_from_proto` for use in `create_noiseless_virtual_engine_from_proto` - Factor out `_create_device_spec_from_template` for use in `create_noiseless_virtual_processor_from_template` and `create_noiseless_virtual_engine_from_templates` - Factor out `MOST_RECENT_TEMPLATES` for use in `create_noiseless_virtual_engine_from_latest_templates` and (manually) in `create_noiseless_virtual_processor_from_template` This unblocks creating one processor at a time for use in quantumlib#4842
We were using `AbstractEngineProcessorShim` pending quantumlib#4644 and friends. Those PRs have landed. For data hygiene as part of the workflow tools, we need to record what processor was used. This PR introduces an abstract `ProcessorRecord` interface and three implementations for mapping (processor_id, whether it's a simulator, what sort of noise) tuples to an AbstractProcessor instance for doing the work. - Remove `AbstractEngineProcessorShim` - Add dataclasses for data hygene - Now we can have proper serialization tests for anything that saves a `QuantumRuntimeConfiguration`, hence the new json files - We don't need to shim over `cirq.read_json` in tests that make use of `AbstractEngineProcessorShim` any more - Side effect: the new engine-processor-backed instances mean we have to use "real" qubits in the tests, so there are some knock-on test changes. cc @dstrain115 @MichaelBroughton
We were using
AbstractEngineProcessorShim
pending #4644 and friends. Those PRs have landed. For data hygiene as part of the workflow tools, we need to record what processor was used. This PR introduces an abstractProcessorRecord
interface and three implementations for mapping (processor_id, whether it's a simulator, what sort of noise) tuples to an AbstractProcessor instance for doing the work.AbstractEngineProcessorShim
QuantumRuntimeConfiguration
, hence the new json filescirq.read_json
in tests that make use ofAbstractEngineProcessorShim
any morecc @dstrain115 @MichaelBroughton