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

Add quil-plotting module #412

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bramathon
Copy link
Collaborator

No description provided.

@bramathon bramathon linked an issue Oct 7, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Oct 7, 2024

PR Preview Action v1.4.8
🚀 Deployed preview to https://rigetti.github.io/quil-rs/pr-preview/pr-412/
on branch quil-py-docs at 2024-10-09 09:51 UTC

Copy link
Contributor

@MarquessV MarquessV left a comment

Choose a reason for hiding this comment

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

Looks like a good start! I wonder how much can be simplified by leveraging quil-py's TemplateWaveforms and expression evaluation. I would also like to see documented examples, and clarification on what needs to be part of the public API here.

RED = "#ef476f" # Magneta
BLUE = "#3d47d9" # Palatinate Blue
GRAY = "#8a8b92" # Gray
NAVY = "#0d0d36" # Cetacean Blue
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these colors configurable? They should be for accessibility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the Rigetti colors. They aren't easily configurable. Any suggestion how to make it so?


[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with using hatchling here.

Copy link
Contributor

Choose a reason for hiding this comment

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

How are these checkpoints used in tests? Since this is a pure Python module, I think a brief CONTRIBUTING.md explaining how to run and test this code would be valuable. I would also add a cargo-make Makefile with tasks to run the tests, at least.

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 is a mistake, will remove.

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a README

"Operating System :: OS Independent",
]
dependencies = [
"numpy>=1.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the mistaken version of numpy, should be 1.21.0 right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup

color_by: str = "Channel Type",
runner_order: str = "Time (s)",
exclude_readout: bool = True,
normalize_by: Optional[str] = "Channel Type",
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 plain strings, can we make "categoricals" and the like enums?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, however I'm not sure if using enums with a pandas dataframe is entirely conventional. I'm not actually sure what best practice would be here.



def deoxidize(num) -> complex:
"""Remove Rust from a Number or PrefixExpression."""
Copy link
Contributor

Choose a reason for hiding this comment

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

This mentions the Number variant, but doesn't handle it. Also, the evaluate method is available on any Expression, and raises an error if it cannot evaluate the expression to a complex number. So this could be simplified to a single line while keeping the same behavior. Since it is a single line, this function can likely be removed.

num.evaluate({}, {})

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 doesn't seem to work on PrefixExpressions. Will revisit it though.

sample_rate = frame["SAMPLE-RATE"].inner().to_real()
match name:
case "flat":
waveform_envelope = FlatWaveform(**parameters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Each of the template waveforms have an into_iq_values method, any reason that isn't used here?

elif isinstance(program, Program):
quil_program = program
else:
raise ValueError("Program must be a pyquil.Program or a quil.Program")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, should this package be aware of pyQuil's internal API? I think it would be better to remove this special case, and add a method to pyQuil's Program that can call into this package instead. That way, implementation details about pyQuil stay in pyQuil.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, removing this is in the TODO.

calibrations = quil_program.calibrations
expanded_quil_program, source_map = expand_with_source_mapping(quil_program, include_pragmas=False)
blocks = expanded_quil_program.control_flow_graph().basic_blocks()
assert len(blocks) == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

ruff should raise a lint for this. In short, assert is removed from optimized Python code, and it's generally better to explicitly raise an error. Reference

@bramathon
Copy link
Collaborator Author

Looks like a good start! I wonder how much can be simplified by leveraging quil-py's TemplateWaveforms and expression evaluation. I would also like to see documented examples, and clarification on what needs to be part of the public API here.

The intention is to use the TemplateWaveforms (I believe this is mentioned in the TODO list and it's actually necessary to avoid a circular dependency with pyquil). At the time of writing, I don't think this feature was released so that's why I made due with the pyquil ones.

As for documentation, what do you have in mind? Should this integrate with the quil-rs documentation?

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.

Create a schedule plotting package
2 participants