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 qargs property, __call__, method to set qargs to BaseOperators #3873

Merged
merged 4 commits into from
Mar 3, 2020

Conversation

chriseclectic
Copy link
Member

@chriseclectic chriseclectic commented Feb 21, 2020

Summary

Closes #3872

Allow subsystem composition and dot using binary operators (eg: op @ x([0]) @ x([1]))

Details and comments

  • Updates operator init functions to avoid copying input data where possible
  • Adds _qargs internal attribute to BaseOperator which is defaulted to None on construction.
  • Adds __call__ method to BaseOperator which allows setting a _qargs value by returning a shallow copy of the current object with _qargs set.
  • Adds qargs property to BaseOperator which returns the value of _qargs.
  • Updates compose and dot methods of all BaseOperator subclasses to use the input objects qargs property if the qargs kwarg is not set.
  • Adds test for shallow copy and subsystem composition using the __call__ method.

@chriseclectic chriseclectic changed the title Add qarg property, __call__, and clone methods to BaseOperators Add qargs property, __call__, method to set qargs to BaseOperators Feb 21, 2020
This property can be set using the __call__ method of the operator. Doing so makes a clone of the operator (doesn't copy underlying data), and can be used with compose/dot functions to automatically infer the qarg kwarg. This allows subsystem composition using binary operators (eg: `op @ x([0]) @ x([1]))

To implement the clone method the default initialization for operators is changed so that it doesn't copy the input data if it is in the correct format.
@kdk kdk added the automerge label Mar 3, 2020
@mergify mergify bot merged commit 6df48fd into Qiskit:master Mar 3, 2020
@chriseclectic chriseclectic added the Changelog: New Feature Include in the "Added" section of the changelog label Apr 2, 2020
@chriseclectic chriseclectic deleted the feature/operator-qargs branch April 3, 2020 16:05
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…ators (Qiskit#3873)

* Add qargs property and clone method to operators

This property can be set using the __call__ method of the operator. Doing so makes a clone of the operator (doesn't copy underlying data), and can be used with compose/dot functions to automatically infer the qarg kwarg. This allows subsystem composition using binary operators (eg: `op @ x([0]) @ x([1]))

To implement the clone method the default initialization for operators is changed so that it doesn't copy the input data if it is in the correct format.

* add tests

* Add release notes

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to compose operators on subsystems using binary operators
3 participants