-
Notifications
You must be signed in to change notification settings - Fork 347
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
Expand calibrations on client side #1271
Conversation
a46d6a8
to
85b8d28
Compare
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The `calibrations` property of `QPUCompiler` provides *cached* access to the calibrations. Upon first using this property a request will be made for the calibration information and may take some time to complete. Subsequent usage of this property will use the cached calibrations and thus will be instantaneous. It should be noted therefore that calibrations **will vary with time** and should be **regularly refreshed** though the specifics of when to refresh the calibrations is left as an exercise for the user. See `QPUCompiler#refresh_calibrations`." |
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.
Instead of exercise for the user (since that's not really an exercise and we are the only source of that information), maybe suggest every 15 minutes. The timeline on which calibrations are refreshed varies per quantum processor, implementation, and our changing internal practices, but every 15 minutes should mean that calibrations are generally never far enough out of date to make an important difference.
pyquil/api/_compiler.py
Outdated
calibrated_program._calibrations = ( | ||
self.calibrations.calibrations + calibrated_program.calibrations | ||
) | ||
calibrated_program._calibrations = self.calibrations + calibrated_program.calibrations | ||
# TODO Only do this if calibrations present in program? |
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.
Seems wise
fd9610c
to
9f01ba6
Compare
pyquil/api/_compiler.py
Outdated
@_record_call | ||
def expand_calibrations(self, program: Program, discard_defcals: bool = True) -> Program: | ||
# Prepend the system's calibrations to the user's calibrations | ||
calibrated_program = self.calibrations + program.copy_everything_except_instructions() |
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.
@kalzoo You'll notice that I switched back to storing the full calibrations program (as provided by get_quilt_calibrations
) rather than just the calibrations
property: the program contains other stuff (waveforms, frames) that we don't want to discard. That means we're back to writing stuff like qc.compiler.calibrations.calibrations
(likewise qc.compiler.calibrations.waveforms
etc.) but I'm not overly worried about that. The +
operator for programs handles calibrations, etc., so adding programs works as expected with later calibrations taking precedence.
Alternatively we could have calibrations
, waveforms
, and frames
properties on QPUCompiler
. That would fix the overloading of the word "calibrations" but otherwise I'm not sure it's an improvement. What do ya think?
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. Let's rename it for clarity then - calibrations
shouldn't be a program, and calibrations.calibrations
makes that apparent. calibrations_program
?
pyquil/api/_compiler.py
Outdated
@_record_call | ||
def expand_calibrations(self, program: Program, discard_defcals: bool = True) -> Program: | ||
# Prepend the system's calibrations to the user's calibrations | ||
calibrated_program = self.calibrations + program.copy_everything_except_instructions() |
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. Let's rename it for clarity then - calibrations
shouldn't be a program, and calibrations.calibrations
makes that apparent. calibrations_program
?
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! Will put this to work very soon in translation.
This introduces a few things: * QPUCompiler#_calibrations is a calibrations cache * QPUCompiler#get_calibrations (formerly QPUCompiler#get_quilt_calibrations) makes an API call to pull the latest calibrations from the translation service. It cares not for any cache. * QPUCompiler#refresh_calibrations grabs the latest calibrations and caches them * QPUCompiler#calibrations is a property that provides access to the cache if it exists, or populates the cache if it doesn't exist. * QPUCompiler#expand_calibrations takes a program, and returns a program where all calibrations are expanded. Calibrations defined in the input program take preference (hopefully) over those in the aforementioned cache.
get_quilt_calibrations() returns more than just the calibrations - it returns a bunch of frame defintions and waveform definitions. Bydoing self._calibrations = get_quilt_calibrations().calibrations we are throwing away the frames/waveforms.
and similar refactors
2be9bad
to
d7ff32d
Compare
* Expand calibrations on the client side This introduces a few things: * QPUCompiler#_calibrations is a calibrations cache * QPUCompiler#get_calibrations (formerly QPUCompiler#get_quilt_calibrations) makes an API call to pull the latest calibrations from the translation service. It cares not for any cache. * QPUCompiler#refresh_calibrations grabs the latest calibrations and caches them * QPUCompiler#calibrations is a property that provides access to the cache if it exists, or populates the cache if it doesn't exist. * QPUCompiler#expand_calibrations takes a program, and returns a program where all calibrations are expanded. Calibrations defined in the input program take preference (hopefully) over those in the aforementioned cache. * Store the calibrations Program rather than calibrations list get_quilt_calibrations() returns more than just the calibrations - it returns a bunch of frame defintions and waveform definitions. Bydoing self._calibrations = get_quilt_calibrations().calibrations we are throwing away the frames/waveforms. * fix style * refactor calibrations -> calibration_program and similar refactors * update notebooks * format
* Expand calibrations on the client side This introduces a few things: * QPUCompiler#_calibrations is a calibrations cache * QPUCompiler#get_calibrations (formerly QPUCompiler#get_quilt_calibrations) makes an API call to pull the latest calibrations from the translation service. It cares not for any cache. * QPUCompiler#refresh_calibrations grabs the latest calibrations and caches them * QPUCompiler#calibrations is a property that provides access to the cache if it exists, or populates the cache if it doesn't exist. * QPUCompiler#expand_calibrations takes a program, and returns a program where all calibrations are expanded. Calibrations defined in the input program take preference (hopefully) over those in the aforementioned cache. * Store the calibrations Program rather than calibrations list get_quilt_calibrations() returns more than just the calibrations - it returns a bunch of frame defintions and waveform definitions. Bydoing self._calibrations = get_quilt_calibrations().calibrations we are throwing away the frames/waveforms. * fix style * refactor calibrations -> calibration_program and similar refactors * update notebooks * format
This introduces a few things:
QPUCompiler#_calibration_program
is a calibrations cacheQPUCompiler#get_calibration_program
(formerlyQPUCompiler#get_quilt_calibrations
) makes an API call to pull thelatest calibrations from the translation service. It cares not for
any cache.
QPUCompiler#refresh_calibration_program
grabs the latest calibrations andcaches them
QPUCompiler#calibration_program
is a property that provides access to thecache if it exists, or populates the cache if it doesn't exist.
QPUCompiler#expand_calibrations
takes a program, and returns aprogram where all calibrations are expanded. Calibrations defined in
the input program take preference (hopefully) over those in the
aforementioned cache.
Closes #1264