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

[Bug Fix] Fix TrotterProduct to be compatible with resource tracking and error tracking #5629

Closed
wants to merge 9 commits into from

Conversation

Jaybsoni
Copy link
Contributor

@Jaybsoni Jaybsoni commented May 2, 2024

Context:
qml.TrotterProduct() now has error tracking functionality, but ins't compatible with resource tracking. This bug fix adds native resource tracking functionality to allow for compatibility with both pipelines.

image

Description of the Change:
Inherit from ResourcesOperation class as well and directly implement the resource method.

Benefits:
Allows for tracking resources without decomposing the template.

Possible Drawbacks:
If we change the target gate-set or want to decompose further, then this method is no longer accurate.

Related GitHub Issues:

@Jaybsoni Jaybsoni added the do not merge ⚠️ Do not merge the pull request until this label is removed label May 2, 2024
@Jaybsoni Jaybsoni requested review from soranjh and DSGuala May 2, 2024 16:58
Copy link
Contributor

github-actions bot commented May 2, 2024

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.

Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (v0.36.0-rc0@e101637). Click here to learn what that means.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.36.0-rc0    #5629   +/-   ##
==============================================
  Coverage               ?   99.69%           
==============================================
  Files                  ?      412           
  Lines                  ?    38352           
  Branches               ?        0           
==============================================
  Hits                   ?    38234           
  Misses                 ?      118           
  Partials               ?        0           

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

@Jaybsoni Jaybsoni requested a review from soranjh May 2, 2024 20:13
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

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

Thanks @Jaybsoni, looks good to go.

Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
@Jaybsoni Jaybsoni requested a review from soranjh May 2, 2024 21:16
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

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

Thanks @Jaybsoni, please split the PR. Thanks.

Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Thanks @Jaybsoni! Leaving a query and couple of suggestions.

num_wires = len(self.wires)
num_gates = len(decomp)

unique_operation_decomp = (copy.deepcopy(op) for op in decomp)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming you want to deep copy this to use it in the tape below? Is that true? Wouldn't it give us a performance hit? 🤔
Also, this is a generator right and not set, so the decomposition need not be unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with the existing decomposition of TrotterProduct, is that it reuses the same operators (with qml.apply). The unique_operation_decomp generator is required to make a new copy of each operator in the decomposition.

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
@astralcai
Copy link
Contributor

As discussed in our standup meeting today, this PR is not expected to be included in the v0.36 release. Can we rebase the PR to the master branch? @Jaybsoni @trbromley

@trbromley
Copy link
Contributor

@Jaybsoni what is easier here, opening a new PR or rebasing this one? CC @DSGuala

@astralcai astralcai deleted the branch v0.36.0-rc0 May 7, 2024 18:11
@astralcai astralcai closed this May 7, 2024
@trbromley trbromley deleted the fix_resource_trotter branch May 8, 2024 13:06
@Jaybsoni
Copy link
Contributor Author

Jaybsoni commented May 8, 2024

It's not very complicated, I can just re-create the PR. Sorry for the delayed response.

Jaybsoni added a commit that referenced this pull request Jun 10, 2024
**Context:**
`qml.TrotterProduct()` now has error tracking functionality, but ins't
compatible with resource tracking. This bug fix adds native resource
tracking functionality to allow for compatibility with both pipelines.


![image](https://github.com/PennyLaneAI/pennylane/assets/21964864/f815b1e5-bf5d-46a0-8539-840013c51d85)

**Description of the Change:**
Inherit from `ResourcesOperation` class as well and directly implement
the resource method.

**Benefits:**
Allows for tracking resources without decomposing the template. 

**Possible Drawbacks:**
If we change the target gate-set or want to decompose further, then this
method is no longer accurate.

**Related GitHub Issues:**
Replicating most of this
[PR](#5629) post release.

---------

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⚠️ Do not merge the pull request until this label is removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants