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

Added examples for vibrational Hamiltonian functions #6717

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ such as `shots`, `rng` and `prng_key`.
and normal-mode localization.
[(#6453)](https://github.com/PennyLaneAI/pennylane/pull/6453)
[(#6666)](https://github.com/PennyLaneAI/pennylane/pull/6666)
[(#6717)](https://github.com/PennyLaneAI/pennylane/pull/6717)
* Implemented helper functions for calculating one-mode PES, two-mode PES, and
three-mode PES.
[(#6616)](https://github.com/PennyLaneAI/pennylane/pull/6616)
Expand Down
55 changes: 35 additions & 20 deletions pennylane/bose/bosonic_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ def binary_mapping(

>>> w = qml.bose.BoseWord({(0, 0): "+"})
>>> qml.binary_mapping(w, n_states=4)
0.6830127018922193 * X(0)
+ -0.1830127018922193 * X(0) @ Z(1)
+ -0.6830127018922193j * Y(0)
+ 0.1830127018922193j * Y(0) @ Z(1)
+ 0.3535533905932738 * X(0) @ X(1)
+ -0.3535533905932738j * X(0) @ Y(1)
+ 0.3535533905932738j * Y(0) @ X(1)
+ (0.3535533905932738+0j) * Y(0) @ Y(1)
(
0.6830127018922193 * X(0)
+ -0.1830127018922193 * X(0) @ Z(1)
+ -0.6830127018922193j * Y(0)
+ 0.1830127018922193j * Y(0) @ Z(1)
+ 0.3535533905932738 * X(0) @ X(1)
+ -0.3535533905932738j * X(0) @ Y(1)
+ 0.3535533905932738j * Y(0) @ X(1)
+ (0.3535533905932738+0j) * Y(0) @ Y(1)
)
"""

qubit_operator = _binary_mapping_dispatch(bose_operator, n_states, tol=tol)
Expand Down Expand Up @@ -190,18 +192,20 @@ def unary_mapping(

>>> w = qml.bose.BoseWord({(0, 0): "+"})
>>> qml.unary_mapping(w, n_states=4)
0.25 * X(0) @ X(1)
+ -0.25j * X(0) @ Y(1)
+ 0.25j * Y(0) @ X(1)
+ (0.25+0j) * Y(0) @ Y(1)
+ 0.3535533905932738 * X(1) @ X(2)
+ -0.3535533905932738j * X(1) @ Y(2)
+ 0.3535533905932738j * Y(1) @ X(2)
+ (0.3535533905932738+0j) * Y(1) @ Y(2)
+ 0.4330127018922193 * X(2) @ X(3)
+ -0.4330127018922193j * X(2) @ Y(3)
+ 0.4330127018922193j * Y(2) @ X(3)
+ (0.4330127018922193+0j) * Y(2) @ Y(3)
(
0.25 * X(0) @ X(1)
+ -0.25j * X(0) @ Y(1)
+ 0.25j * Y(0) @ X(1)
+ (0.25+0j) * Y(0) @ Y(1)
+ 0.3535533905932738 * X(1) @ X(2)
+ -0.3535533905932738j * X(1) @ Y(2)
+ 0.3535533905932738j * Y(1) @ X(2)
+ (0.3535533905932738+0j) * Y(1) @ Y(2)
+ 0.4330127018922193 * X(2) @ X(3)
+ -0.4330127018922193j * X(2) @ Y(3)
+ 0.4330127018922193j * Y(2) @ X(3)
+ (0.4330127018922193+0j) * Y(2) @ Y(3)
)
"""

qubit_operator = _unary_mapping_dispatch(bose_operator, n_states, tol=tol)
Expand Down Expand Up @@ -334,6 +338,17 @@ def christiansen_mapping(

Returns:
Union[PauliSentence, Operator]: A linear combination of qubit operators.

**Example**

>>> w = qml.bose.BoseWord({(0,0):"+", (1,1): "-"})
>>> qml.christiansen_mapping(w)
(
0.25 * (X(0) @ X(1))
+ 0.25j * (X(0) @ Y(1))
+ -0.25j * (Y(0) @ X(1))
+ (0.25+0j) * (Y(0) @ Y(1))
)
"""

qubit_operator = _christiansen_mapping_dispatch(bose_operator, tol)
Expand Down
16 changes: 16 additions & 0 deletions pennylane/qchem/vibrational/localize_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ def localize_normal_modes(freqs, vecs, bins=[2600]):
- TensorLike[float] : localization matrix describing the relationship between
original and localized modes.

**Example**
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved

>>> freqs = np.array([1326.66001461, 2297.26736859, 2299.65032901])
>>> vectors = np.array([[[ 5.71518696e-18, -4.55642350e-01, 5.20920552e-01],
[ 1.13167924e-17, 4.55642350e-01, 5.20920552e-01],
[-1.23163569e-17, 5.09494945e-12, -3.27565762e-02]],
[[-4.53008817e-17, 4.90364125e-01, 4.90363894e-01],
[-1.98591028e-16, 4.90361513e-01, -4.90361744e-01],
[-2.78235498e-18, -3.08350419e-02, -6.75886679e-08]],
[[ 5.75393451e-17, 5.37047963e-01, 4.41957355e-01],
[ 6.53049347e-17, -5.37050348e-01, 4.41959740e-01],
[-5.49709883e-17, 7.49851221e-08, -2.77912798e-02]]])
>>> freqs_loc, vecs_loc, uloc = qml.qchem.localize_normal_modes(freqs, vectors)
>>> freqs_loc
array([1332.62008773, 2296.73455892, 2296.7346082 ])

"""
if not bins:
raise ValueError("The `bins` list cannot be empty.")
Expand Down
33 changes: 33 additions & 0 deletions pennylane/qchem/vibrational/vibrational_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ class VibrationalPES:
1, 2, or 3 for upto one-mode dipole, two-mode dipole and three-mode dipole, respectively. Default
value is 1.

**Example**

>>> freqs = np.array([0.01885397])
>>> grid, weights = np.polynomial.hermite.hermgauss(9)
>>> pes_onebody = [[0.05235573, 0.03093067, 0.01501878, 0.00420778, 0.0,
0.00584504, 0.02881817, 0.08483433, 0.22025702]]
>>> pes_twobody = None
>>> dipole_onebody = [[[-1.92201700e-16, 1.45397041e-16, -1.40451549e-01],
[-1.51005108e-16, 9.53185441e-17, -1.03377032e-01],
[-1.22793018e-16, 7.22781963e-17, -6.92825934e-02],
[-1.96537436e-16, -5.86686504e-19, -3.52245369e-02],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 5.24758835e-17, -1.40650833e-16, 3.69955543e-02],
[-4.52407941e-17, 1.38406311e-16, 7.60888733e-02],
[-4.63820104e-16, 5.42928787e-17, 1.17726042e-01],
[ 1.19224372e-16, 9.12491386e-17, 1.64013197e-01]]]
>>> vib_obj = qml.qchem.VibrationalPES(freqs=freqs, grid=grid, gauss_weights=weights,
uloc = None, pes_data=[pes_onebody, pes_twobody],
dipole_data=[dipole_onebody], localized=False)
>>> vib_obj.freqs
array([0.01885397])

"""

def __init__(
Expand Down Expand Up @@ -150,6 +172,17 @@ def optimize_geometry(molecule, method="rhf"):
Returns:
array[array[float]]: optimized atomic positions in Cartesian coordinates

**Example**

>>> symbols = ['H', 'F']
>>> geometry = np.array([[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0]])
>>> mol = qml.qchem.Molecule(symbols, geometry)
>>> eq_geom = qml.qchem.optimize_geometry(mol)
>>> eq_geom
array([[ 0. , 0. , -0.40277116],
[ 0. , 0. , 1.40277116]])

"""
pyscf = _import_pyscf()
geometric = _import_geometric()
Expand Down
Loading