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 function to convert PennyLane objects to OpenFermion objects #5759

Closed
soranjh opened this issue May 29, 2024 · 2 comments · Fixed by #5773
Closed

Add function to convert PennyLane objects to OpenFermion objects #5759

soranjh opened this issue May 29, 2024 · 2 comments · Fixed by #5773
Labels
enhancement ✨ New feature or request

Comments

@soranjh
Copy link
Contributor

soranjh commented May 29, 2024

Feature details

⚠️ This issue is part of an internal assignment and not meant for external contributors.

PennyLane has several functions and classes for creating and manipulating qubit and fermionic operators. It will be useful to have functions that allow converting between PennyLane operations and OpenFermion objects. These new functions, called to_openfermion and from_openfermion , should allow users to

>>> import pennylane as qml
>>> pl_term = 1.2 * qml.X(0) + 2.4 * qml.Z(1)
>>> of_term = to_openfermion(pl_term)
>>> of_term
1.2 [X0] + 2.4 [Z1]
>>> import pennylane as qml
>>> of_term = QubitOperator('X0', 1.2) + QubitOperator('Z1', 2.4)
>>> pl_term = from_openfermion(of_term, wires = {0: 'a', 1: 'b'})
>>> pl_term
1.2 * X('a') + 2.4 * Z('b')

Implementation

The to_openfermion and from_openfermion functions should be placed in a new module called pennylane.qchem.convert_openfermion and be importable as

>>> import pennylane as qml
>>> qml.to_openfermion(...)
>>> qml.from_openfermion(...)

Requirements

  1. The from_openfermion function should have a wires argument accepting a dictionary for custom wire mapping.
  2. The from_openfermion function should have a tol argument for discarding the imaginary part of the coefficients.
  3. Both functions should be properly tested.
@dariavh
Copy link
Contributor

dariavh commented May 31, 2024

Hi @soranjh ,

Thank you for providing detailed guidelines for the assignment. I have implemented the requested features in PR #5773. Could you confirm if we only need the tol and wires arguments for the from_openfermion method, while these can also be implemented for to_openfermion?

Additionally, the codecov test keeps failing, even when the coverage of my two adjusted files qchem/convert.py and qchem/convert_openfermion.py has a 100% coverage.

@soranjh
Copy link
Contributor Author

soranjh commented May 31, 2024

Hi @soranjh ,

Thank you for providing detailed guidelines for the assignment. I have implemented the requested features in PR #5773. Could you confirm if we only need the tol and wires arguments for the from_openfermion method, while these can also be implemented for to_openfermion?

Additionally, the codecov test keeps failing, even when the coverage of my two adjusted files qchem/convert.py and qchem/convert_openfermion.py has a 100% coverage.

Thanks @dariavh. You can also add tol and wires arguments for to_openfermion. We will explore the codecov test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants