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

[Frontend] Make tests toml-schema independent #712

Merged
merged 27 commits into from
May 24, 2024
Merged

Conversation

grwlf
Copy link
Contributor

@grwlf grwlf commented May 3, 2024

Context: Transition to the quantum device config schema 2

Description of the Change: Solve a regarding toml schema 2 udpate in tests by switching our test custom devices from toml text manipulations to the device capability manipulations

Benefits:

  • Tests no longer require toml text manipulations.
  • Tests now contain simple examples of custom devices.
  • toml-specific code is now locates in catalyst.utils.toml.

Possible Drawbacks:

Related GitHub Issues:
PennyLaneAI/pennylane-lightning#642

@grwlf grwlf marked this pull request as ready for review May 3, 2024 12:22
@grwlf grwlf requested a review from dime10 May 3, 2024 12:23
@grwlf grwlf self-assigned this May 3, 2024
@grwlf grwlf changed the title Make a test tomle-schema-2-compatible Make decomposition test tomle-schema-2-compatible May 3, 2024
@dime10
Copy link
Collaborator

dime10 commented May 3, 2024

Good point, we could just make it compatible with both. I was just going to move to version 2 entirely once the PR is merged. I'm happy with this as well though.

Note there are several other tests that need this update though :)

@grwlf
Copy link
Contributor Author

grwlf commented May 3, 2024

Note there are several other tests that need this update though :)

@dime10 , are there? I think I changed the device which is used by several tests, and can't see other places.

@dime10
Copy link
Collaborator

dime10 commented May 3, 2024

Note there are several other tests that need this update though :)

@dime10 , are there? I think I changed the device which is used by several tests, and can't see other places.

Have a look at the test_decomposition and test_quantum_control lit tests

Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 97.01493% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 98.07%. Comparing base (47b3482) to head (eadeb91).

Files Patch % Lines
frontend/catalyst/device/qjit_device.py 95.12% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #712   +/-   ##
=======================================
  Coverage   98.07%   98.07%           
=======================================
  Files          70       70           
  Lines        9599     9601    +2     
  Branches      754      756    +2     
=======================================
+ Hits         9414     9416    +2     
  Misses        151      151           
  Partials       34       34           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grwlf grwlf changed the title Make decomposition test tomle-schema-2-compatible [Frontend] Make tests tomle-schema independent May 6, 2024
@grwlf
Copy link
Contributor Author

grwlf commented May 6, 2024

Have a look at the test_decomposition and test_quantum_control lit tests

@dime10 right, thanks! I have made these tests toml-independent. It required some further code reshaping, could you please review?

@grwlf grwlf changed the title [Frontend] Make tests tomle-schema independent [Frontend] Make tests toml-schema independent May 6, 2024
@grwlf grwlf mentioned this pull request May 9, 2024
5 tasks
frontend/catalyst/utils/toml.py Outdated Show resolved Hide resolved
frontend/catalyst/qfunc.py Outdated Show resolved Hide resolved
@grwlf grwlf requested a review from dime10 May 16, 2024 12:09
Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Thanks I think this PR is almost good to go. The only thing I would ask to restrict the utils/toml module to be more focused on interacting with the toml file format, rather than including functionality related to device capabilities (it is a utility module after all).

frontend/catalyst/compiler.py Outdated Show resolved Hide resolved
frontend/catalyst/jax_primitives.py Outdated Show resolved Hide resolved
frontend/catalyst/third_party/cuda/primitives/__init__.py Outdated Show resolved Hide resolved
return set(operations_no_adj)


def validate_device_capabilities(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This module is just here to abstract away interacting with a TOML file right (and abstracting away from schema differences)? Validating device capabilities once the toml file has been processed then seems unrelated to interacting with the toml format. In that case I would prefer having this in the catalyst/device submodule, along with some of the other functions that don't interact with the toml file (I'm not 100% where the boundary should be the, probably anything that requires the device instance).

Copy link
Contributor Author

@grwlf grwlf May 24, 2024

Choose a reason for hiding this comment

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

Done.
I personally think that it is not possible to find a perfect locations for code in Python+OOP style, so I am trying to focus on observable things only, like cyclic dependencies. The problem is in the fact that in this style we define types and methods simultaneously when we define classes (one per module), which forces some hierarchy. In practice, in contrast, we often need to process several equally-important types using a single algorithm. For my projects I (1) limit usage of "normal" classes (2) create types.py for all mypy types and dataclases (3) group functions in -py files trying to localize groups of cyclic deps among functions one per file.

Copy link
Collaborator

@dime10 dime10 May 24, 2024

Choose a reason for hiding this comment

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

What about get_device_toml_config and get_device_capabilities, their code seems to be operating primarily on the device, and then call into toml functions like read_toml_file and load_device_capabilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Where?

@grwlf grwlf requested a review from dime10 May 24, 2024 11:57
Comment on lines +100 to +101
* Catalyst tests now manipulate device capabilities rather than text configurations files.
[(#712)](https://github.com/PennyLaneAI/catalyst/pull/712)
Copy link
Collaborator

@dime10 dime10 May 24, 2024

Choose a reason for hiding this comment

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

Reading this entry it sounds like it only concerns tests. Typically we exclude changelog entries for test-only, ci-only, doc-only, and repo-only changes.
Maybe the refactor can be mentioned in internal changes though? 🤔 New features, improvements, bug fixes should all be observable by the user in the distributed release in some way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok done

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the commit changed anything?

return set(operations_no_adj)


def validate_device_capabilities(
Copy link
Collaborator

@dime10 dime10 May 24, 2024

Choose a reason for hiding this comment

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

What about get_device_toml_config and get_device_capabilities, their code seems to be operating primarily on the device, and then call into toml functions like read_toml_file and load_device_capabilities?

@grwlf grwlf merged commit 715523e into main May 24, 2024
41 of 42 checks passed
@grwlf grwlf deleted the toml-schema-2-update-test branch May 24, 2024 14:50
grwlf added a commit that referenced this pull request May 27, 2024
**Context:** Catalyst needs to deal with operations which are not
supported by the target device. This PR addresses
decomposition-to-matrix branch.

**Description of the Change:** We read gates to be decomposed to matrix
from the device capabilities (which in turn are described in the device
toml file).
[sc-62011]

**Benefits:** Device authors gain control over the decomposition
strategies

**Possible Drawbacks:**

**Related GitHub Issues:**
Requires #712

---------

Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
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.

None yet

3 participants