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

Raise ValueError when trying to create PhaseDiagram without entries #2819

Merged
merged 4 commits into from
Jan 30, 2023

Conversation

peikai
Copy link
Contributor

@peikai peikai commented Jan 28, 2023

I committed some codes to raise a specific ValueError exception and hint a specific reason message for the attempt to build a phase diagram with no entries. A corresponding unittest was also added.

Scenario:
In the cases that there are not enough entries to form a complete phase diagram, the processing operation of the mixing scheme would fail and might return an empty list, i.e., entryList = []. That would cause an error in PhaseDiagram class when computing data, as shown below. To raise a specific exception is necessary.

Run:

entryList = MaterialsProjectDFTMixingScheme().process_entries(entryList, clean=True)
phase_diagram = PhaseDiagram(entryList)

Errors:

Generating mixing state data from provided entries.
D:\Anaconda\envs\pymatgen2023\Lib\site-packages\pymatgen\entries\mixing_scheme.py:508: UserWarning: GGA(+U) entries do not form a complete PhaseDiagram.
warnings.warn(f"{self.run_type_1} entries do not form a complete PhaseDiagram.")
Entries contain R2SCAN calculations for 0 of 0 GGA(+U) hull entries.
GGA(+U) energies will be adjusted to the R2SCAN scale
D:\Anaconda\envs\pymatgen2023\Lib\site-packages\pymatgen\entries\mixing_scheme.py:215: UserWarning: WARNING! GGA(+U) entries do not form a complete PhaseDiagram. No energy adjustments will be applied.
warnings.warn(str(exc))
Processing complete. Mixed entries contain 0 GGA(+U) and 0 R2SCAN entries.

Traceback (most recent call last):
phase_diagram = PhaseDiagram(entryList)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda\envs\pymatgen2023\Lib\site-packages\pymatgen\analysis\phase_diagram.py", line 366, in init
computed_data = self._compute()
^^^^^^^^^^^^^^^
File "D:\Anaconda\envs\pymatgen2023\Lib\site-packages\pymatgen\analysis\phase_diagram.py", line 445, in _compute
form_e = -np.dot(data, vec)
^^^^^^^^^^^^^^^^^
File "<array_function internals>", line 180, in dot
ValueError: shapes (0,) and (1,) not aligned: 0 (dim 0) != 1 (dim 0)

@coveralls
Copy link

coveralls commented Jan 28, 2023

Coverage Status

Coverage: 78.165% (-0.7%) from 78.875% when pulling a047696 on peikai:EmptyEntryList into ef98f0b on materialsproject:master.

@janosh janosh changed the title Raise ValueError when building phase diagram without entries. Raise ValueError when trying to create PhaseDiagram without entries Jan 29, 2023
@janosh janosh enabled auto-merge (squash) January 29, 2023 23:59
@janosh
Copy link
Member

janosh commented Jan 29, 2023

Thanks @peikai! 👍

@janosh janosh merged commit 04b4d1f into materialsproject:master Jan 30, 2023
@peikai peikai deleted the EmptyEntryList branch January 30, 2023 12:07
@peikai
Copy link
Contributor Author

peikai commented Jan 30, 2023

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants