Skip to content

Algo Benchmark Library card catalog #235

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

Merged
merged 13 commits into from
Dec 8, 2021
Merged

Conversation

mpharrigan
Copy link
Collaborator

This "card catalog" will be the centralized record of algorithmic benchmarks that are highly organized and use the new cirq_google.workflow cirqflow style of execution.

This PR does not commit any benchmarks, but establishes (via the dataclasses and the tests) a set of conventions for organizing things.

Change-Id: I4ca692cd92ddbee95d0d2aeed5a4027fcd0f2aa4


@dataclass
class AlgoBenchmark:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we call this AlgorithmBenchmark? It is more verbose, but abbreviations are generally discouraged:
cirq-google/cirq_google/engine/engine_program.py

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 77e48f9

@dataclass
class AlgoBenchmark:
domain: str
"""The problem domain. Usually a high-level ReCirq module."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the proper way to document this class? I thought the usual way to document these was to have a docstring at the beginning of the class with an "Args" section that describes each parameter.

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 9481205

data_class: Type
"""The class which can contain ETL-ed data for this AlgoBenchmark."""

gen_func: Callable[[...], QuantumExecutableGroup]
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 also an abbreviation. Maybe generator would be a better name?

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 6f9224c



@lru_cache()
def get_all_algo_configs() -> List[Tuple[AlgoBenchmark, BenchmarkConfig]]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing docstring.

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 8f139ec



def main():
df = pd.DataFrame([algo.as_strings() for algo in BENCHMARKS]).set_index('executable_family')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Heh. This is a funny way of printing out the benchmark names. You are using pandas just for text formatting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sortof forgot I left this in here. Changed the name of this function and removed the __main__ entry point 1514b20

The nice thing about pandas is you can use the same technique in a juypter noteook and get a nice html table that you can paste into sheets or a doc

@dataclass
class AlgoBenchmark:
domain: str
"""The problem domain. Usually a high-level ReCirq module."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Usually a high-level ReCirq module." This is actually enforced by the tests, so I would adjust the wording to make it mandatory and also make clear that it should include the "recirq." prefix.

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 7c7faa1

@pytest.mark.parametrize('algo', BENCHMARKS)
def test_executable_family_is_formulaic(algo):
# Check consistency in the AlgoBenchmark dataclass:
assert algo.executable_family == algo.spec_class.executable_family
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these are checking consistency for future benchmarks, it might be good to add messages to this assert and other asserts in this file so that developers of benchmarks know why their tests are failing.

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 3308c5e

"""A globally unique name for this config."""

gen_script: str
"""The script filename that generates the QuantumExecutableGroup for this Config."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should include that the gen-script should begin with "gen-". Same for other test-enforced conventions.

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 69b6b65

Change-Id: Ic95e07f4690f4f10bf2634eda7a66ac81649774a
Change-Id: Ic1213396a235f6e40e46d2f3472d8380bb653719
Change-Id: I97e19c6544def983cadde8c959fbc83b5d9f867e
Change-Id: I7c23fa8eac6d0b04cc7a480ac6a81cf4cb29f308
Change-Id: I21a65e3e126c42bb227582d335d24a3fca287015
Change-Id: Ic393c5bb90b6df5b50b9a70ae0b3386d43a89e6f
Change-Id: I95696873269c5e66dcbffedce7814c4488ac6d47
Change-Id: I04cd53462b7190e071cd6ec680aaec37e08e7064
Change-Id: I7a78669ee18d47a4e909783663c2da210d1db699
Copy link
Collaborator Author

@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.

ptal



@dataclass
class AlgoBenchmark:
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 77e48f9

@dataclass
class AlgoBenchmark:
domain: str
"""The problem domain. Usually a high-level ReCirq module."""
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 9481205

@dataclass
class AlgoBenchmark:
domain: str
"""The problem domain. Usually a high-level ReCirq module."""
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 7c7faa1

data_class: Type
"""The class which can contain ETL-ed data for this AlgoBenchmark."""

gen_func: Callable[[...], QuantumExecutableGroup]
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 6f9224c

"""A globally unique name for this config."""

gen_script: str
"""The script filename that generates the QuantumExecutableGroup for this Config."""
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 69b6b65



@lru_cache()
def get_all_algo_configs() -> List[Tuple[AlgoBenchmark, BenchmarkConfig]]:
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 8f139ec



def main():
df = pd.DataFrame([algo.as_strings() for algo in BENCHMARKS]).set_index('executable_family')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sortof forgot I left this in here. Changed the name of this function and removed the __main__ entry point 1514b20

The nice thing about pandas is you can use the same technique in a juypter noteook and get a nice html table that you can paste into sheets or a doc

@pytest.mark.parametrize('algo', BENCHMARKS)
def test_executable_family_is_formulaic(algo):
# Check consistency in the AlgoBenchmark dataclass:
assert algo.executable_family == algo.spec_class.executable_family
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 3308c5e

Copy link
Collaborator

@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.

LGTM once the tests resolve.


import pandas as pd

from cirq_google.workflow import ExecutableSpec, QuantumExecutableGroup
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the pytest:

ModuleNotFoundError: No module named 'cirq_google.workflow'

Is this waiting on another PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This and other forthcoming code relies on the currently-unreleased cirq_google.workflow module. I'll have to figure out a way to make this work in the mean time.

  1. release openfermion that doesn't pin to a particular cirq version
  2. enable testing against multiple versions of cirq including prerelease in ReCirq CI
  3. put import guards and conditional testing so these tests only run if a recent enough cirq version is available

Copy link
Collaborator Author

@mpharrigan mpharrigan Dec 7, 2021

Choose a reason for hiding this comment

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

Following #237 , this is now implemented. The tests get run on the current and next config. They were failing on cirq 0.12. Looks like the executable spec stuff got included in v0.13 but future functionality may only be tested on next until the relevant cirq release is cut.

Change-Id: I1ae995491202c2b2f00c1614cb3c5623080ac685
Change-Id: I55a4e61783f337c7220f85b36fef61391138e0d9
Change-Id: I350ce16324e64d0c1e8d14d56737ea090b3fc039
@mpharrigan mpharrigan merged commit fee620b into master Dec 8, 2021
@mpharrigan mpharrigan deleted the 2021-12-algo-library branch December 8, 2021 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants