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

Deprecate MeasurementProcess.return_type and ObservableReturnTypes #6841

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Jan 15, 2025

Context:
The MeasurementProcess.return_type is only used by the legacy device in a chain of if mp.return_type.name is ... checks that can easily be replaced with isinstance checks.

In PL0.40, return_type is a property of MeasurementProcess which returns None only. Meanwhile, ObservableReturnTypes is an Enum that defines and wraps the name strings, redundantly.

Description of the Change:

  • raise deprecation warnings in return_type.
  • replace legacy device usages of return_type with direct isinstance check
  • unwrap ObservableReturnTypes with direct definitions.
  • subclasses that overrode return_type: ExpectationMP, ProbabilityMP, SampleMP, StateMP, CountsMP and VarianceMP

Benefits:
Less redundancies.

Possible Drawbacks:
any downstreaming usage of the deprecations:

  • lightning: 6 usages in _adjoint_jacobian_base.py, lightning_base.py and test_measurements.py. Occurrencies here actually block this PR
  • catalyst
  • qml
  • plugins

Related GitHub Issues:
[sc-71892]

@JerryChen97 JerryChen97 self-assigned this Jan 15, 2025
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@JerryChen97 JerryChen97 added the deprecation 🗑️ Deprecating an API or user-facing feature/behaviour label Jan 15, 2025
@JerryChen97 JerryChen97 marked this pull request as ready for review January 17, 2025 21:29
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (cb883b1) to head (9c6c620).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6841   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files         476      476           
  Lines       45194    45185    -9     
=======================================
- Hits        45015    45008    -7     
+ Misses        179      177    -2     

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

@@ -56,27 +56,27 @@ def test_serialize_numeric_arguments(self, queue, observable_queue, expected_str
observable3 = qml.prod(qml.PauliZ(0), qml.PauliZ(1))

numeric_observable_queue = [
(returntype1, observable1, "|||ObservableReturnTypes.Expectation!PauliZ[0]"),
(returntype1, observable1, "|||ExpectationMP!PauliZ[0]"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

QQ: after deprecating return type and replacing occurrences with isinstance, we might have to replace the expected output texts in circuit_graph with the exact class names. Is this a harmless change here? @albi3ro @astralcai
Also, in this module do we have any secondary applications from these return type information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another question: is doc/development/guide/architecture.rst also within the scope of deprecations/removals? It defines MP.return_type there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

QQ: after deprecating return type and replacing occurrences with isinstance, we might have to replace the expected output texts in circuit_graph with the exact class names. Is this a harmless change here? @albi3ro @astralcai Also, in this module do we have any secondary applications from these return type information?

I see another usecase in drawer: tape_text.py:_add_measurement and _add_cwire_measurement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, return_type has been built into the repr of MP...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, return_type has been built into the repr of MP...

solution: make repr equivalents individually for each subclass of MP.
reason: we definitely want to get rid of the Enum of obs short name list, but on the other hand we should not touch any public interfaces that use these pieces of information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation 🗑️ Deprecating an API or user-facing feature/behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant