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

Extending support for larger atomic numbers #5821

Merged
merged 22 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4571cb6
initial update
obliviateandsurrender Jun 7, 2024
4cc50c6
add a `unittest`
obliviateandsurrender Jun 7, 2024
ac176cf
Update doc/releases/changelog-dev.md
obliviateandsurrender Jun 14, 2024
aacd874
Merge branch 'master' into atomic-numbers-upgrade
obliviateandsurrender Jun 17, 2024
bdbdb65
add suggestions
obliviateandsurrender Jun 17, 2024
7545a03
Merge branch 'atomic-numbers-upgrade' of https://github.com/PennyLane…
obliviateandsurrender Jun 17, 2024
916edcf
Merge branch 'master' into atomic-numbers-upgrade
obliviateandsurrender Jun 17, 2024
333e90f
minor test tweak
obliviateandsurrender Jun 18, 2024
600af65
Merge branch 'atomic-numbers-upgrade' of https://github.com/PennyLane…
obliviateandsurrender Jun 18, 2024
404e0a4
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
obliviateandsurrender Jun 18, 2024
15066e8
Merge branch 'master' into atomic-numbers-upgrade
obliviateandsurrender Jun 20, 2024
ff53e0c
apply suggestions
obliviateandsurrender Jul 17, 2024
9212e8b
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
obliviateandsurrender Jul 17, 2024
c6246d9
marker note
obliviateandsurrender Jul 17, 2024
3424891
error message tweak
obliviateandsurrender Jul 17, 2024
c39ec48
update error message
obliviateandsurrender Jul 17, 2024
ae47fe5
Merge branch 'master' into atomic-numbers-upgrade
obliviateandsurrender Jul 17, 2024
ae74831
typo
obliviateandsurrender Jul 17, 2024
e1482dd
Merge branch 'atomic-numbers-upgrade' of https://github.com/PennyLane…
obliviateandsurrender Jul 17, 2024
3a62e27
Merge branch 'master' into atomic-numbers-upgrade
obliviateandsurrender Jul 18, 2024
a0f282a
update message
obliviateandsurrender Jul 18, 2024
be0ecf5
Merge branch 'atomic-numbers-upgrade' of https://github.com/PennyLane…
obliviateandsurrender Jul 18, 2024
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
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
* The qchem module has dedicated functions for calling `pyscf` and `openfermion` backends.
[(#5553)](https://github.com/PennyLaneAI/pennylane/pull/5553)

* Molecules and Hamiltonians can be constructed for elements present in the periodic table.
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
[(#5821)](https://github.com/PennyLaneAI/pennylane/pull/5821)

<h4>Mid-circuit measurements and dynamic circuits</h4>

* Rationalize MCM tests, removing most end-to-end tests from the native MCM test file,
Expand Down Expand Up @@ -359,6 +362,7 @@
This release contains contributions from (in alphabetical order):

Guillermo Alonso-Linaje,
Utkarsh Azad
Lillian M. A. Frederiksen,
Gabriel Bottrill,
Astral Cai,
Expand Down
37 changes: 25 additions & 12 deletions pennylane/qchem/basis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@

import itertools

# fmt: off
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
atomic_numbers = {
"H": 1,
"He": 2,
"Li": 3,
"Be": 4,
"B": 5,
"C": 6,
"N": 7,
"O": 8,
"F": 9,
"Ne": 10,
'H': 1, 'He': 2, # Period 1
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
'Li': 3, 'Be': 4, 'B': 5, 'C': 6, 'N': 7, 'O': 8, 'F': 9, 'Ne': 10, # Period 2
'Na': 11, 'Mg': 12, 'Al': 13, 'Si': 14, 'P': 15, 'S': 16, 'Cl': 17, 'Ar': 18, # Period 3
'K': 19, 'Ca': 20, 'Sc': 21, 'Ti': 22, 'V': 23, 'Cr': 24, 'Mn': 25, 'Fe': 26, 'Co': 27, # Period 4
'Ni': 28, 'Cu': 29, 'Zn': 30, 'Ga': 31, 'Ge': 32, 'As': 33, 'Se': 34, 'Br': 35, 'Kr': 36,
'Rb': 37, 'Sr': 38, 'Y': 39, 'Zr': 40, 'Nb': 41, 'Mo': 42, 'Tc': 43, 'Ru': 44, 'Rh': 45, # Period 5
'Pd': 46, 'Ag': 47, 'Cd': 48, 'In': 49, 'Sn': 50, 'Sb': 51, 'Te': 52, 'I': 53, 'Xe': 54,
'Cs': 55, 'Ba': 56, # Period 6
'La': 57, 'Ce': 58, 'Pr': 59, 'Nd': 60, 'Pm': 61, 'Sm': 62, 'Eu': 63, 'Gd': 64, 'Tb': 65, # Lanthanides
'Dy': 66, 'Ho': 67, 'Er': 68, 'Tm': 69, 'Yb': 70, 'Lu': 71,
'Hf': 72, 'Ta': 73, 'W': 74, 'Re': 75, 'Os': 76, 'Ir': 77, 'Pt': 78, 'Au': 79, 'Hg': 80, # Period 6
'Tl': 81, 'Pb': 82, 'Bi': 83, 'Po': 84, 'At': 85, 'Rn': 86,
'Fr': 87, 'Ra': 88, # Period 7
'Ac': 89, 'Th': 90, 'Pa': 91, 'U': 92, 'Np': 93, 'Pu': 94, 'Am': 95, 'Cm': 96, 'Bk': 97, # Actinides
'Cf': 98, 'Es': 99, 'Fm': 100, 'Md': 101, 'No': 102, 'Lr': 103,
'Rf': 104, 'Db': 105, 'Sg': 106, 'Bh': 107, 'Hs': 108, 'Mt': 109, 'Ds': 110, 'Rg': 111, # Period 7
'Cn': 112, 'Nh': 113, 'Fl': 114, 'Mc': 115, 'Lv': 116, 'Ts': 117, 'Og': 118
}
# fmt: on
soranjh marked this conversation as resolved.
Show resolved Hide resolved


STO3G = {
"H": {
Expand Down Expand Up @@ -797,11 +807,14 @@ def load_basisset(basis, element):
"[3]": "F",
"[4]": "G",
"[5]": "H",
"[6]": "I",
}

element = str(atomic_numbers[element])
atomic_number = atomic_numbers.get(element, None)
if atomic_number is None:
raise ValueError(f"Requested element {element} doesn't exist in the periodic table.")

data = bse.get_basis(basis)["elements"][element]["electron_shells"]
data = bse.get_basis(basis)["elements"][str(atomic_number)]["electron_shells"]

orbitals = []
exponents = []
Expand Down
9 changes: 9 additions & 0 deletions pennylane/qchem/basis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def atom_basis_data(name, atom, load_data=False):
if load_data:
basis = load_basisset(name, atom)
else:
basis = basis_sets[name].get(atom, None)
if basis is None:
raise ValueError(
"Currently, internally supported basis sets: 'sto-3g', '6-31g', '6-311g' and "
"'cc-pvdz', support only first- or second-row elements of the periodic table. "
"Please consider using `load_data=True` to download an extended version of "
f"{basis_sets[name]} from an external library that can be installed with: "
"pip install basis-set-exchange."
)
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
basis = basis_sets[name][atom]

params = []
Expand Down
5 changes: 1 addition & 4 deletions pennylane/qchem/openfermion_pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,7 @@ def dipole_of(

for i in symbols:
if i not in atomic_numbers:
raise ValueError(
f"Currently, only first- or second-row elements of the periodic table are supported;"
f" got element {i}"
)
raise ValueError(f"Requested element {i} doesn't exist in the periodic table")
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved

hf_file = qml.qchem.meanfield(symbols, coordinates, name, charge, mult, basis, package, outpath)

Expand Down
2 changes: 1 addition & 1 deletion tests/qchem/of_tests/test_dipole_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def circuit(hf_state, obs):
("symbols", "coords", "mult", "msg_match"),
[
(["H", "H"], x_h2, 2, "this functionality is constrained to Hartree-Fock states"),
(["H", "Ca"], x_h2, 1, "only first- or second-row elements of the periodic table"),
(["H", "Cx"], x_h2, 1, "Requested element Cx doesn't exist in the periodic table"),
],
)
@pytest.mark.usefixtures("skip_if_no_openfermion_support")
Expand Down
9 changes: 9 additions & 0 deletions tests/qchem/test_basis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,15 @@ def test_mol_basis_data(self, basis_data):

assert np.allclose(params, params_ref)

def test_mol_basis_data_error(self):
"""Test that correct error is raised if the element is not present in the internal basis-sets"""

with pytest.raises(ValueError, match="Currently, internally supported basis sets"):
qchem.basis_set.atom_basis_data(name="sto-3g", atom="Os")

with pytest.raises(ValueError, match="doesn't exist in the periodic table"):
qchem.basis_data.load_basisset(basis="sto-3g", element="Ox")


class TestLoadBasis:
"""Tests for loading data from external libraries."""
Expand Down
2 changes: 1 addition & 1 deletion tests/qchem/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_basis_error(self, symbols, geometry):
@pytest.mark.parametrize(
("symbols", "geometry"),
[
(["H", "Og"], np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])),
(["H", "Ox"], np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])),
],
)
def test_symbol_error(self, symbols, geometry):
Expand Down
Loading