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

Expand calibrations on client side #1271

Merged
merged 6 commits into from
Nov 19, 2020

Conversation

notmgsk
Copy link
Contributor

@notmgsk notmgsk commented Nov 11, 2020

This introduces a few things:

  • QPUCompiler#_calibration_program is a calibrations cache

  • QPUCompiler#get_calibration_program (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_calibration_program grabs the latest calibrations and
    caches them

  • QPUCompiler#calibration_program 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.

Closes #1264

@notmgsk notmgsk changed the base branch from master to quilt-demo November 11, 2020 20:09
@notmgsk notmgsk force-pushed the 1264-expand-calibrations-on-client-side branch 2 times, most recently from a46d6a8 to 85b8d28 Compare November 12, 2020 19:08
@notmgsk notmgsk marked this pull request as ready for review November 13, 2020 13:33
@notmgsk notmgsk requested a review from a team as a code owner November 13, 2020 13:33
pyquil/api/_compiler.py Outdated Show resolved Hide resolved
pyquil/api/_compiler.py Show resolved Hide resolved
pyquil/tests/test_quilt.py Outdated Show resolved Hide resolved
pyquil/api/_compiler.py Outdated Show resolved Hide resolved
pyquil/api/_compiler.py Show resolved Hide resolved
"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`."
Copy link
Contributor

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.

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?
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems wise

@notmgsk notmgsk force-pushed the 1264-expand-calibrations-on-client-side branch from fd9610c to 9f01ba6 Compare November 19, 2020 21:13
@_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()
Copy link
Contributor Author

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?

Copy link
Contributor

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?

@_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()
Copy link
Contributor

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?

Copy link
Contributor

@kalzoo kalzoo left a 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.
@notmgsk notmgsk force-pushed the 1264-expand-calibrations-on-client-side branch from 2be9bad to d7ff32d Compare November 19, 2020 23:02
@notmgsk notmgsk merged commit 76538f9 into quilt-demo Nov 19, 2020
notmgsk added a commit that referenced this pull request Nov 24, 2020
* 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
notmgsk added a commit that referenced this pull request Nov 25, 2020
* 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
@dbanty dbanty deleted the 1264-expand-calibrations-on-client-side branch February 14, 2022 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expand Quilt Calibrations on Client
2 participants