-
Notifications
You must be signed in to change notification settings - Fork 575
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
[OpRefactor] Update eigenvalue representations #2048
Conversation
Hello. You may have forgotten to update the changelog!
|
pennylane/operation.py
Outdated
@@ -481,66 +481,71 @@ def matrix(self, wire_order=None): | |||
return expand_matrix(canonical_matrix, wires=self.wires, wire_order=wire_order) | |||
|
|||
@classmethod | |||
def _eigvals(cls, *params): | |||
def compute_eigvals(cls, *params, **hyperparams): | |||
"""Eigenvalues of the operator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: I did this inconsistently so far, but would like to call this the "canonical" eigenvalues, and explain that these are the eigenvalues wrt the canonical matrix. To me this was never clear, but it may just be me?
In this case, is there a clear path to and merit in adding wires, wire_order
arguments to eigvals
below? Since there is no order to them anyways? I don't think so myself...
x_apply_diag_init = [ | ||
[1, PauliZ(0), basis_state(0, 1)], | ||
[2, CZ(wires=[0, 1]), basis_state(0, 2)], | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar change to other PR: The _get_kraus
method now expects instances...
Codecov Report
@@ Coverage Diff @@
## op-refactor #2048 +/- ##
===============================================
+ Coverage 99.18% 99.25% +0.06%
===============================================
Files 225 225
Lines 17268 17187 -81
===============================================
- Hits 17128 17059 -69
+ Misses 140 128 -12
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the class methods should be static methods?
Apart from that, a straightforward PR!
pennylane/operation.py
Outdated
""" | ||
return np.linalg.eigvals(cls.compute_matrix(*params)) | ||
return np.linalg.eigvals(cls.compute_matrix(*params, **hyperparams)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we replace this with qml.math.linalg.eigvals
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not right now? It sounds like a bigger unscheduled change?
@@ -1182,7 +1189,7 @@ def _kraus_matrices(cls, *params): | |||
[0. , 0. ]])] | |||
|
|||
To return the Kraus matrices of an *instantiated* channel, | |||
please use the :attr:`~.Operator.kraus_matrices` property instead. | |||
please use the :meth:`~.Operator.kraus_matrices` property instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snuck those ones in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mariaschuld! I must admit I still find the class method odd compared to the other static methods, but:
- I see why it is needed
- I can't think of anything better
Oh wait!!!!!!! Sorry I just had an idea literally while typing this out.
What if we keep compute_eigvals
a static method, but we put the default logic in eigvals
?
For example:
def eigvals(self):
try:
return self.compute_eigvals(*self.parameters, **self.hyperparameters)
except EigenvaluesUndefined:
return np.linalg.eigvals(self.compute_matrix(*self.parameters, **self.hyperparameters))
To me this straight away makes a lot of sense; eigvals
here is trying to perform automated logic that involves calling some combination of compute_
methods, depending on what is defined :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Maria for implementing this change, it feels much more standardized now! I only caught one class method that should be a static method
@classmethod | ||
def _matrix(cls, *params): | ||
basis_state = params[0] | ||
m = np.zeros((2 ** len(basis_state), 2 ** len(basis_state))) | ||
idx = int("".join(str(i) for i in basis_state), 2) | ||
m[idx, idx] = 1 | ||
return m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this was deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the method in a separate PR, and it merged it into the dev branch although the matrix refactor already introduced another one...
* remove string_for_inverse * fix accidental push * [OpRefractor] remove `string_for_inverse` (#2021) * remove string_for_inverse * remove string_for_inverse for device * black * Update doc/releases/changelog-dev.md * [OpRefactor] add temporary hyperparameter attribute (#2017) * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Move diagonalizing_gates method to Operator (#1985) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * polish * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * Update the `Operation.generator` property (#2030) * more * more * more * more * fixes * fixes * all tests passing * fix * more * Apply suggestions from code review * add to changelog * [OpRefactor] Add static compute_diagonalizing_gates method (#1993) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * add compute_diag_gates method * backup * add test and attribute * black * polish * polish signatures * black * fix docstring * fix signature * polish * make wires an arg * fix coverage * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * change signatures * improve docstring * small fix * Apply suggestions from code review * better docstrings * add examples everywhere * more docstring polish * add docstring for identity * hermitian better example * black * suggestions code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Fix dev branch after merging master (#2047) * use get_generator func * add a lot of pylints * fix failing test * move pylints * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Upgrade matrix methods (#1996) * change matrix methods * clean up basic methods * changed matrix to matrix() * black * fix test * fix Hadamard gate * changelog * fix some more small issues * some more fixes * make (almost) all _matrix methods static * backup * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * blackup * wrote up new usage * correct changelog * add some tests for expand-matrix * black * fix some tests * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * replace expand logic in get_unitary * fix multirz inverse * fix minor pauli_eigs error * fix qft error * resolve conflict * fix all test but the BIG ISSUE * change signature, part 1 * finish dosctrings * black * all minor problems cleared again * polish * more polish and black * fix docstrings, fix ControlledQubitUNitary * changelog polish * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * implement suggestions josh * black * redesigned ControlledQubitUnitary * backup * revert to NotImplementedErrors * typo * black * delete superfluous matrix methods * delete superfluous arg * fix tests * black * hopefully fix failing test * fix codecoverage * fix last coverage issue * backup * add hyperparameters and pylints * black * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Add terms and compute_terms (#2036) * black and changelog * fix typo * fixed fermionic terms * black * backup * fix * simpler implementation * minor updates * fix some tests * fix tests * polishing * add test * fix docstring formatting * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions josh * Update pennylane/ops/qubit/hamiltonian.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * add pylints (#2052) * [OpRefactor] Rename wires as wire_order in heisenberg ops (#2051) * rename * update changelog * [OpRefactor] Update eigenvalue representations (#2048) * fix tests * black * increase codecov * black * josh suggestions * move default to eigvals() and make everything static * apply suggestions josh * Apply suggestions from code review * [OpRefactor] Add sparse_matrix and compute_sparse_matrix methods (#2050) * basic changes * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * josh suggestions Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Update kraus representations (#2055) * rename * dicstrings * fix docstring * minor fix to test * Update doc/releases/changelog-dev.md * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] `decomposition` and `compute_decomposition` methods in `Operator` base class (#2024) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * remove unused import * black, fix multicontrolledx * fix tests, black * fixing more tests * hopefully the last breaking tests * enhance code coverage * fix some problems from merging * pin sphinx Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * [OpRefactor] Update the generator to raise an exception if not defined (#2061) * Update the generator to raise an exception if not defined * fixes * fixes * fixes * fix * [OpRefactor] Add custom errors when representations are undefined (#2064) * add errors and tests, use errors * small fix * change one more None to Error * delete obsolete line * fix tests * black * update changelog * [OpRefactor] fix codefactor (#2067) * fix codefactor * restore lines * delete again * `Tensor.matrix`: Warnings for partial wires overlaps and unsorted wire repetition (#2013) * implement sorting before grouping and check partial wires overlaps. * changelog * black * tests * tiny * reduce PR to warnings * lint * old python sum * black * code review * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * restructure warning logic * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * changes applied * Apply suggestions from code review * black * one more test fixed * [OpRefactor] Update dev guide to explain the new operator abstraction (#2066) * add previous changes * add graphic * rewrite architecture overview * rewrite op guide * add differentiation * fomatting * polish * polish * polish * black * formatting * fix sphinx? * some dashes * josh comments * major polish * minor details * minor improvement * more polishing * fix link * fix qasm precision * changing qasm tests back * Update doc/development/adding_operators.rst Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions Josh 1 * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * minor improvements * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update doc/development/guide/architecture.rst * Update doc/development/adding_operators.rst * change images, fix link Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update Operation call signatures to match doc string (#1976) * Updated parameteric_ops to match docs call signature * finished updating all of the ops * Added wires arg to SparseHamiltonian * updating some of cv ops * updating call signature for more ops * updated callsigns * updated changelog * disable too many args error for code factor * replaced lam with delta * Removed Sphinx Override * fixed bug with TensorN observable * Update doc/releases/changelog-dev.md Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> * [OpRefactor] Use decomposition in templates (#2053) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * embeddings started to refactor * embeddings done * backup * layers done * statepreps done * backup * done subroutines * backup * fix tests except grover, timeevol, commuting * black * fix last three tests * black * black * fix tests * mottonnen fixed * update changelog * fixes, including sphinx * backup * Fix tape expand tests (#2065) * fixes * more * more * more * more * more * more * black * delete faulty import * improve codecoverage * improve coverage by one line * port one bug fix from other branch * backup * suggestions Josh 1 * redo changes in reset files * rewrite op_list extension * black * fix tests * change ttn * make pylint happy * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> * black * black * revert * adapt isingzz eval function * backup * fix all tests except from the batch one * upgraded version of black and blackened again * [OpRefactor] Final clean-up of operator subclasses (#2131) * dummy change to open pr * clean docstrings * backup * port some changes from operation.py PR * clean docstrings of classes * black * minor sphinx fix * make docstrings similar * more cleaning, and revert BasisStatePrep for test passing * black * upgraded version of black and blackened again * fix * fix * fix bug * merge master * linting * remove print label * [WIP] Renaming (#2189) * more * more * more * more * more * more * more * rename eigvals to get_eigvals() * black * update eigvals in tests * tensor eigvals * fix * more * Update pennylane/operation.py Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * update deprecation warning * more * add deprecation tests Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * coverage Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: David Wierichs <davidwierichs@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com>
* remove string_for_inverse * fix accidental push * [OpRefractor] remove `string_for_inverse` (#2021) * remove string_for_inverse * remove string_for_inverse for device * black * Update doc/releases/changelog-dev.md * [OpRefactor] add temporary hyperparameter attribute (#2017) * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Move diagonalizing_gates method to Operator (#1985) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * polish * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * Update the `Operation.generator` property (#2030) * more * more * more * more * fixes * fixes * all tests passing * fix * more * Apply suggestions from code review * add to changelog * [OpRefactor] Add static compute_diagonalizing_gates method (#1993) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * add compute_diag_gates method * backup * add test and attribute * black * polish * polish signatures * black * fix docstring * fix signature * polish * make wires an arg * fix coverage * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * change signatures * improve docstring * small fix * Apply suggestions from code review * better docstrings * add examples everywhere * more docstring polish * add docstring for identity * hermitian better example * black * suggestions code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Fix dev branch after merging master (#2047) * use get_generator func * add a lot of pylints * fix failing test * move pylints * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Upgrade matrix methods (#1996) * change matrix methods * clean up basic methods * changed matrix to matrix() * black * fix test * fix Hadamard gate * changelog * fix some more small issues * some more fixes * make (almost) all _matrix methods static * backup * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * blackup * wrote up new usage * correct changelog * add some tests for expand-matrix * black * fix some tests * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * replace expand logic in get_unitary * fix multirz inverse * fix minor pauli_eigs error * fix qft error * resolve conflict * fix all test but the BIG ISSUE * change signature, part 1 * finish dosctrings * black * all minor problems cleared again * polish * more polish and black * fix docstrings, fix ControlledQubitUNitary * changelog polish * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * implement suggestions josh * black * redesigned ControlledQubitUnitary * backup * revert to NotImplementedErrors * typo * black * delete superfluous matrix methods * delete superfluous arg * fix tests * black * hopefully fix failing test * fix codecoverage * fix last coverage issue * backup * add hyperparameters and pylints * black * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Add terms and compute_terms (#2036) * black and changelog * fix typo * fixed fermionic terms * black * backup * fix * simpler implementation * minor updates * fix some tests * fix tests * polishing * add test * fix docstring formatting * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions josh * Update pennylane/ops/qubit/hamiltonian.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * add pylints (#2052) * [OpRefactor] Rename wires as wire_order in heisenberg ops (#2051) * rename * update changelog * [OpRefactor] Update eigenvalue representations (#2048) * fix tests * black * increase codecov * black * josh suggestions * move default to eigvals() and make everything static * apply suggestions josh * Apply suggestions from code review * [OpRefactor] Add sparse_matrix and compute_sparse_matrix methods (#2050) * basic changes * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * josh suggestions Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Update kraus representations (#2055) * rename * dicstrings * fix docstring * minor fix to test * Update doc/releases/changelog-dev.md * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] `decomposition` and `compute_decomposition` methods in `Operator` base class (#2024) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * remove unused import * black, fix multicontrolledx * fix tests, black * fixing more tests * hopefully the last breaking tests * enhance code coverage * fix some problems from merging * pin sphinx Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * [OpRefactor] Update the generator to raise an exception if not defined (#2061) * Update the generator to raise an exception if not defined * fixes * fixes * fixes * fix * [OpRefactor] Add custom errors when representations are undefined (#2064) * add errors and tests, use errors * small fix * change one more None to Error * delete obsolete line * fix tests * black * update changelog * [OpRefactor] fix codefactor (#2067) * fix codefactor * restore lines * delete again * `Tensor.matrix`: Warnings for partial wires overlaps and unsorted wire repetition (#2013) * implement sorting before grouping and check partial wires overlaps. * changelog * black * tests * tiny * reduce PR to warnings * lint * old python sum * black * code review * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * restructure warning logic * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * changes applied * Apply suggestions from code review * black * one more test fixed * [OpRefactor] Update dev guide to explain the new operator abstraction (#2066) * add previous changes * add graphic * rewrite architecture overview * rewrite op guide * add differentiation * fomatting * polish * polish * polish * black * formatting * fix sphinx? * some dashes * josh comments * major polish * minor details * minor improvement * more polishing * fix link * fix qasm precision * changing qasm tests back * Update doc/development/adding_operators.rst Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions Josh 1 * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * minor improvements * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update doc/development/guide/architecture.rst * Update doc/development/adding_operators.rst * change images, fix link Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update Operation call signatures to match doc string (#1976) * Updated parameteric_ops to match docs call signature * finished updating all of the ops * Added wires arg to SparseHamiltonian * updating some of cv ops * updating call signature for more ops * updated callsigns * updated changelog * disable too many args error for code factor * replaced lam with delta * Removed Sphinx Override * fixed bug with TensorN observable * Update doc/releases/changelog-dev.md Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> * [OpRefactor] Use decomposition in templates (#2053) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * embeddings started to refactor * embeddings done * backup * layers done * statepreps done * backup * done subroutines * backup * fix tests except grover, timeevol, commuting * black * fix last three tests * black * black * fix tests * mottonnen fixed * update changelog * fixes, including sphinx * backup * Fix tape expand tests (#2065) * fixes * more * more * more * more * more * more * black * delete faulty import * improve codecoverage * improve coverage by one line * port one bug fix from other branch * backup * suggestions Josh 1 * redo changes in reset files * rewrite op_list extension * black * fix tests * change ttn * make pylint happy * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> * black * black * revert * adapt isingzz eval function * backup * fix all tests except from the batch one * upgraded version of black and blackened again * [OpRefactor] Final clean-up of operator subclasses (#2131) * dummy change to open pr * clean docstrings * backup * port some changes from operation.py PR * clean docstrings of classes * black * minor sphinx fix * make docstrings similar * more cleaning, and revert BasisStatePrep for test passing * black * upgraded version of black and blackened again * first step * reduce step * undo has_gen * tests * changelog * restore grad_recipe * black * fix orbitalrotation gradient * docstring * lint * add gradient bug fix for OrbitalRotaiton to changelog * fix * tests for parameter frequencies * test coverage * copy JacobianTape methods to parameter_shift.py * fix * Revert "copy JacobianTape methods to parameter_shift.py" This reverts commit 3be9806. * use parameter_frequencies for shift rule. adapt tests. add parameter_frequencies to operation.grad_method * black * changelog * whitespace * debugging * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * add eight-term rule to OrbitalRotation * formatting of frequencies * orbital * doc * make frequencies a property * test * adapt tests to frequencies being property * adapt to parameter_frequencies as property * adapt more tests * more * more * simplify util functions a bit * fix bug * merge master * linting * remove print label * [WIP] Renaming (#2189) * more * more * more * more * more * more * more * rename eigvals to get_eigvals() * black * update eigvals in tests * tensor eigvals * fix * more * Update pennylane/operation.py Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * update deprecation warning * more * add deprecation tests Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * test coverage * lint * lint abstractmethod * coverage * tests for default grad_method * remove old prints * test coverage * black * undo move of JacobianTape methods * pointless statement is not pointless * black * some linting * print reintroduce * wrong local pylint * more fiddling with pylint * docstring shifts * test_draw * test_draw_1 * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * drawing tests * make _process_shifts public * rename no_duplicates to check_duplicates * remove unnecessary lint disable * black * merge master Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com>
* remove string_for_inverse * fix accidental push * [OpRefractor] remove `string_for_inverse` (#2021) * remove string_for_inverse * remove string_for_inverse for device * black * Update doc/releases/changelog-dev.md * [OpRefactor] add temporary hyperparameter attribute (#2017) * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Move diagonalizing_gates method to Operator (#1985) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * polish * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * Update the `Operation.generator` property (#2030) * more * more * more * more * fixes * fixes * all tests passing * fix * more * Apply suggestions from code review * add to changelog * [OpRefactor] Add static compute_diagonalizing_gates method (#1993) * move method and update docstrings in evals * black * revert to NotImplementedError * fix queuing issue * add compute_diag_gates method * backup * add test and attribute * black * polish * polish signatures * black * fix docstring * fix signature * polish * make wires an arg * fix coverage * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * change signatures * improve docstring * small fix * Apply suggestions from code review * better docstrings * add examples everywhere * more docstring polish * add docstring for identity * hermitian better example * black * suggestions code review Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Fix dev branch after merging master (#2047) * use get_generator func * add a lot of pylints * fix failing test * move pylints * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Upgrade matrix methods (#1996) * change matrix methods * clean up basic methods * changed matrix to matrix() * black * fix test * fix Hadamard gate * changelog * fix some more small issues * some more fixes * make (almost) all _matrix methods static * backup * add test and attribute * black * fix coverage * polish * changelog * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * blackup * wrote up new usage * correct changelog * add some tests for expand-matrix * black * fix some tests * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * replace expand logic in get_unitary * fix multirz inverse * fix minor pauli_eigs error * fix qft error * resolve conflict * fix all test but the BIG ISSUE * change signature, part 1 * finish dosctrings * black * all minor problems cleared again * polish * more polish and black * fix docstrings, fix ControlledQubitUNitary * changelog polish * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * implement suggestions josh * black * redesigned ControlledQubitUnitary * backup * revert to NotImplementedErrors * typo * black * delete superfluous matrix methods * delete superfluous arg * fix tests * black * hopefully fix failing test * fix codecoverage * fix last coverage issue * backup * add hyperparameters and pylints * black * Update pennylane/operation.py Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> * [OpRefactor] Add terms and compute_terms (#2036) * black and changelog * fix typo * fixed fermionic terms * black * backup * fix * simpler implementation * minor updates * fix some tests * fix tests * polishing * add test * fix docstring formatting * Update pennylane/operation.py Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions josh * Update pennylane/ops/qubit/hamiltonian.py Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * add pylints (#2052) * [OpRefactor] Rename wires as wire_order in heisenberg ops (#2051) * rename * update changelog * [OpRefactor] Update eigenvalue representations (#2048) * fix tests * black * increase codecov * black * josh suggestions * move default to eigvals() and make everything static * apply suggestions josh * Apply suggestions from code review * [OpRefactor] Add sparse_matrix and compute_sparse_matrix methods (#2050) * basic changes * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * josh suggestions Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] Update kraus representations (#2055) * rename * dicstrings * fix docstring * minor fix to test * Update doc/releases/changelog-dev.md * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * black Co-authored-by: Josh Izaac <josh146@gmail.com> * [OpRefactor] `decomposition` and `compute_decomposition` methods in `Operator` base class (#2024) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * remove unused import * black, fix multicontrolledx * fix tests, black * fixing more tests * hopefully the last breaking tests * enhance code coverage * fix some problems from merging * pin sphinx Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * [OpRefactor] Update the generator to raise an exception if not defined (#2061) * Update the generator to raise an exception if not defined * fixes * fixes * fixes * fix * [OpRefactor] Add custom errors when representations are undefined (#2064) * add errors and tests, use errors * small fix * change one more None to Error * delete obsolete line * fix tests * black * update changelog * [OpRefactor] fix codefactor (#2067) * fix codefactor * restore lines * delete again * `Tensor.matrix`: Warnings for partial wires overlaps and unsorted wire repetition (#2013) * implement sorting before grouping and check partial wires overlaps. * changelog * black * tests * tiny * reduce PR to warnings * lint * old python sum * black * code review * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * restructure warning logic * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> * changes applied * Apply suggestions from code review * black * one more test fixed * [OpRefactor] Update dev guide to explain the new operator abstraction (#2066) * add previous changes * add graphic * rewrite architecture overview * rewrite op guide * add differentiation * fomatting * polish * polish * polish * black * formatting * fix sphinx? * some dashes * josh comments * major polish * minor details * minor improvement * more polishing * fix link * fix qasm precision * changing qasm tests back * Update doc/development/adding_operators.rst Co-authored-by: Josh Izaac <josh146@gmail.com> * suggestions Josh 1 * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * backup * minor improvements * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update doc/development/guide/architecture.rst * Update doc/development/adding_operators.rst * change images, fix link Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> * Update Operation call signatures to match doc string (#1976) * Updated parameteric_ops to match docs call signature * finished updating all of the ops * Added wires arg to SparseHamiltonian * updating some of cv ops * updating call signature for more ops * updated callsigns * updated changelog * disable too many args error for code factor * replaced lam with delta * Removed Sphinx Override * fixed bug with TensorN observable * Update doc/releases/changelog-dev.md Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com> * [OpRefactor] Use decomposition in templates (#2053) * decomposition and compute decomposition methods * adding some more ops * more consistent across qubit ops, return as tuple * start adding templates * move hyperparameters defintions * update templates in a later PR * tests * fixing tests * more test fixes * final test fix! * docstrings, interface device tests * black, tests for coverage * changelog and docstrings * docstrings * more child class docstrings * Update doc/releases/changelog-dev.md Co-authored-by: Josh Izaac <josh146@gmail.com> * nodecompositionerror, test new docstrings * docstring fixes * merge conflict * docstring fixes and minor updates * barrier doc change * test fixing, parametric op docstrings * final docstrings, black * qft docstring * black, fix test * embeddings started to refactor * embeddings done * backup * layers done * statepreps done * backup * done subroutines * backup * fix tests except grover, timeevol, commuting * black * fix last three tests * black * black * fix tests * mottonnen fixed * update changelog * fixes, including sphinx * backup * Fix tape expand tests (#2065) * fixes * more * more * more * more * more * more * black * delete faulty import * improve codecoverage * improve coverage by one line * port one bug fix from other branch * backup * suggestions Josh 1 * redo changes in reset files * rewrite op_list extension * black * fix tests * change ttn * make pylint happy * black * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> * black * black * revert * adapt isingzz eval function * backup * fix all tests except from the batch one * upgraded version of black and blackened again * [OpRefactor] Final clean-up of operator subclasses (#2131) * dummy change to open pr * clean docstrings * backup * port some changes from operation.py PR * clean docstrings of classes * black * minor sphinx fix * make docstrings similar * more cleaning, and revert BasisStatePrep for test passing * black * upgraded version of black and blackened again * first step * reduce step * undo has_gen * tests * changelog * restore grad_recipe * black * fix orbitalrotation gradient * docstring * lint * add gradient bug fix for OrbitalRotaiton to changelog * fix * tests for parameter frequencies * test coverage * copy JacobianTape methods to parameter_shift.py * fix * Revert "copy JacobianTape methods to parameter_shift.py" This reverts commit 3be9806. * use parameter_frequencies for shift rule. adapt tests. add parameter_frequencies to operation.grad_method * black * changelog * whitespace * debugging * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> * add eight-term rule to OrbitalRotation * formatting of frequencies * orbital * doc * make frequencies a property * test * adapt tests to frequencies being property * adapt to parameter_frequencies as property * adapt more tests * more * more * simplify util functions a bit * fix bug * merge master * linting * remove print label * [WIP] Renaming (#2189) * more * more * more * more * more * more * more * rename eigvals to get_eigvals() * black * update eigvals in tests * tensor eigvals * fix * more * Update pennylane/operation.py Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * update deprecation warning * more * add deprecation tests Co-authored-by: Maria Schuld <mariaschuld@gmail.com> * test coverage * lint * lint abstractmethod * coverage * tests for default grad_method * remove old prints * test coverage * black * undo move of JacobianTape methods * pointless statement is not pointless * black * some linting * print reintroduce * wrong local pylint * more fiddling with pylint * docstring shifts * move methods away from JacobianTape to gradients module * black * also use moved methods for finite diff * remove old print * make methods public Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Maria Schuld <mariaschuld@gmail.com> Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca> Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: DSGuala <67476785+DSGuala@users.noreply.github.com> Co-authored-by: antalszava <antalszava@gmail.com>
Context:
Applies the new design to eigenvalues.
Description of the Change:
Renaming, make
eigvals
a proper method, add some docstrings and examples.Possible Drawbacks:
Didn't add tests. We should probably do this, but in interest of time I just rely on the old tests.