api icon indicating copy to clipboard operation
api copied to clipboard

[Bug]: Retrieving "entry" for tasks no longer works

Open tawe141 opened this issue 3 months ago • 5 comments

Code snippet

with MPRester() as mpr:
    task_id = 'mp-19970'
    task_doc = mpr.materials.tasks.search([task_id], fields=['task_id', 'calcs_reversed', 'elements', 'entry'])[0]
    print(task_doc.entry)

What happened?

I'm attempting to retrieve the entries in TaskDocs, and I've been including 'entry' in the fields requested. However, the error below, stating that 'entry' is not part of the document, occurs when I run the above snippet. Despite including this in fields, the resulting document has 'entry' in fields_not_requested. Strangely, this was working even without including 'entry' explicitly in fields last week. Has something changed with the API?

Version

0.45.12

Which OS?

  • [ ] MacOS
  • [ ] Windows
  • [x] Linux

Log output

AttributeError: 'entry' data is available but has not been requested in 'fields'. A full list of unrequested fields can be found in `fields_not_requested`.

tawe141 avatar Oct 16 '25 21:10 tawe141

Thanks for reporting this! We think we know the issue and are already in the process of shipping a fix. We'll update here when it's live. Thank you for your patience!

tschaume avatar Oct 16 '25 21:10 tschaume

Actually, this looks like an unrelated issue. @tsmathis @esoteric-ephemera I can reproduce this with the latest mp-api and emmet-core version. Any ideas?

tschaume avatar Oct 17 '25 00:10 tschaume

We switched to using CoreTaskDoc in the tasks collection to permit indexing. CoreTaskDoc doesn't have an entry field like the full TaskDoc, which it inherits from. Additionally, the get_entry function from TaskDoc isn't carried over to MPDataDoc.

@tawe141 here's an extension of your if you need the entries from only searching tasks, and don't want to use the thermo endpoint to obtain them:

from emmet.core.tasks import TaskDoc

task_doc = TaskDoc(**task_doc.model_dump())
print(task_doc.entry)
>>> mp-19970 ComputedEntry - Li12 Cu4 O12 (Li3CuO3)
Energy (Uncorrected)     = -140.1340 eV (-5.0048  eV/atom)
Correction               = 0.0000    eV (0.0000   eV/atom)
Energy (Final)           = -140.1340 eV (-5.0048  eV/atom)
Energy Adjustments:
  None
Parameters:
  potcar_spec            = [{'titel': 'PAW_PBE Li_sv 23Jan2001', 'hash': '4799bab014a83a07c654d7196c8ecfa9', 'summary_stats': None}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982', 'summary_stats': None}, {'titel': 'PAW_PBE Cu_pv 06Sep2000', 'hash': '2d718b6be91068094207c9e861e11a89', 'summary_stats': None}]
  run_type               = GGA
  is_hubbard             = False
  hubbards               = None
Data:
  oxide_type             = oxide
  aspherical             = False
  last_updated           = 2025-10-17 15:41:38.007278+00:00

You could make it a bit more efficient like this:

task_id = 'mp-19970'
with MPRester(use_document_model=False) as mpr:
    task_doc = mpr.materials.tasks.search([task_id], fields=['task_id', 'calcs_reversed', 'elements', 'entry'])[0]
task_doc = TaskDoc(**task_doc)

~Might need to work on this so the AlphaID doesn't get carried through to the entry.~ Actually looks like this is already fixed in develop but maybe not in main

esoteric-ephemera avatar Oct 17 '25 15:10 esoteric-ephemera

Thanks for the workaround @esoteric-ephemera ! I'm not sure if this is a bug that needs fixing or if the workaround is sufficient, so I'll leave the issue open for now. Feel free to close this if you'd like to.

tawe141 avatar Oct 17 '25 20:10 tawe141

Hey @tawe141 thanks for your patience. After some internal discussion, we're planning not to include the entry with tasks since these entries duplicate information already in the task. Also, the entries you'd get from the materials.thermo endpoint will include important corrections that are not included with the tasks.

If you do need the entry for a particular purpose, here's a maybe faster way to generate them from a task, just note where the duplication of fields comes from. Might be easier to migrate your code to just using existing attributes on a task:

from pymatgen.entries.computed_entries import ComputedEntry,ComputedStructureEntry

def get_entry(task, include_structure : bool = False) -> ComputedEntry | ComputedStructureEntry:
    conf = {
        "composition": task.output.structure.composition,
        "energy": task.output.energy,
        "entry_id": task.task_id,
        "correction": 0.,
        "parameters": {
            "run_type": task.run_type
        }
    }
    pmg_cls = ComputedEntry
    if include_structure:
        conf["structure"] = task.output.structure
        pmg_cls = ComputedStructureEntry
    return pmg_cls(**conf)

Also just to make sure, when you were querying tasks in the past and retrieved an entry with them, did you use materials.tasks directly?

esoteric-ephemera avatar Oct 22 '25 00:10 esoteric-ephemera