-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Context:** This PR adds the functionality to convert a ``QubitOperator`` in OpenFermion to a ``LinearCombination`` in PennyLane and vice versa. **Description of the Change:** Added `convert_openfermion` module to `qchem` where users are able to convert a `QubitOperator` object from OpenFermion into a `LinearCombination` object in PennyLane using `from_openfermion`. Conversion of a `LinearCombination` object to `QubitOperator` object is implemented in `to_openfermion`. **Benefits:** Directly convert the operator in terms of a ``LinearCombination`` object instead of the current functionality where a list of coefficients and operators is needed (see `_pennylane_to_openfermion` and `_openfermion_to_pennylane` methods in [convert.py](https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/qchem/convert.py)). **Possible Drawbacks:** If we provide a custom wire mapping where we e.g. swap the order of the wires, the `LinearCombination` object is still given in the order of the unswapped wires. However, the order of the operators should only matter for printing anyway. ``` >>> q_op = openfermion.QubitOperator("X0", 1.2) + openfermion.QubitOperator("Z1", 2.4) + openfermion.QubitOperator("Y2", 0.1) >>> q_op 1.2 [X0] + 2.4 [Z1] + 0.1 [Y2] >>> pl_linear_combination = qml.from_openfermion(q_op, wires={0: 2, 1: 1, 2: 0}) >>> pl_linear_combination 1.2 * X(2) + 2.4 * Z(1) + 0.1 * Y(0) ``` **Related GitHub Issues:** Closes #5759. --------- Co-authored-by: soranjh <[email protected]> Co-authored-by: Thomas R. Bromley <[email protected]> Co-authored-by: soranjh <[email protected]>
- Loading branch information
1 parent
c874bbd
commit 11d3d93
Showing
8 changed files
with
582 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.