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

Fix error in 'qml.data.load()` when using 'full' parameter value #4663

Merged

Conversation

brownj85
Copy link
Contributor

@brownj85 brownj85 commented Oct 10, 2023

Context:
qml.data.load() did not properly handle specified parameters that come after 'full'. For example, the following
call should return all qspin datasets matching sysname='Heisenberg', periodicity='open', layout='2x2', for any value
of lattice:

qml.data.load('qspin',sysname='Heisenberg',periodicity='open',lattice='full',layout='2x2')

Instead, we get an exception, even though matching datasets do exist:

ValueError: layout value of '2x2' is not available. Available values are ['1x16', '1x4', '1x8']

This happens because the find() function fails as soon as it can't find a matching dataset for any of the parameters. When it checks the 'chain' lattice, it can't find '2x2' and throws an exception, even though '2x2' is available for 'rectangular'.

Description of the Change:
Foldermap.find() will only throw an exception if it cannot find any matching datasets for a given parameter. This does mean that the user can provide invalid parameters, as long as one of them matches. For example:

qml.data.load('qspin',sysname='Heisenberg',periodicity='open',lattice='full',layout=['2x2', '17x32'])

Will not result in an error.

Benefits:

  • qml.data.load() can handle full parameters that come before specific parameters.

Possible Drawbacks:

  • The user will not get immediate feedback for erroneous parameters
  • Users are no logner guaranteed to get a dataset for every combination of (fully qualified) parameters. For example, qml.data.load('qchem', molname='H2', basis=['STO-3G', 'CC-PVDZ'], bondlength=['0.5', '0.7']) will return 4 datasets. But if one those is removed, 3 will be returned without throwing an error.

Related GitHub Issues:
Fixes #4270

@brownj85 brownj85 marked this pull request as ready for review October 11, 2023 16:51
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (4c3ab72) 99.64% compared to head (b42047e) 99.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4663   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         376      376           
  Lines       33828    33833    +5     
=======================================
+ Hits        33707    33712    +5     
  Misses        121      121           
Files Coverage Δ
pennylane/data/data_manager/foldermap.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! just clarifying something you said:

...basis=['STO-3G', 'CC-PVDZ'], bondlength=['0.5', '0.7']) will return 4 datasets. But if one those is removed, 3 will be returned without throwing an error.

if one what is removed? and which 3 will be returned? I'm not entirely sure what the expected behaviour is there.

tests/data/data_manager/test_foldermap.py Show resolved Hide resolved
@brownj85
Copy link
Contributor Author

if one what is removed? and which 3 will be returned? I'm not entirely sure what the expected behaviour is there.

So before this PR, if H2_CC-PVDZ_0.7 was removed from the datasets bucket (and the foldermap), calling
qml.data.load('qchem', molname='H2', basis=['STO-3G', 'CC-PVDZ'], bondlength=['0.5', '0.7']) would cause an exception, because one of the requested parameter combinations doesn't exist. After this PR it'll return the other 3 datasets without an exception. An exception is only raised if none of the requested parameter combinations exist.

There's not really an 'expected' behaviour here (afaik) so we're not breaking any promises.

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh gotcha - you mean removed from the actual database, makes sense! looks great :shipit:

Copy link
Contributor

@DSGuala DSGuala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, not getting the error anymore 💯

@brownj85 brownj85 enabled auto-merge (squash) October 16, 2023 18:59
@brownj85 brownj85 merged commit b45f808 into master Oct 16, 2023
39 checks passed
@brownj85 brownj85 deleted the sc-40483-bug-qml-data-load-fails-when-using-full-parameter branch October 16, 2023 19:43
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.

[BUG] qml.data.load() fails when using 'full' parameter value
3 participants