Skip to content
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
3 changes: 2 additions & 1 deletion tools/nexus_eln/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ hand-written detection answers.
| builder | `afm_header.json`, `flt_header.json` | A header marker (text and JSON header) wins over the extension; the conflict is reported |
| builder | `answer_detect_afm.md`, `answer_detect_sts.md` | A found quote wins; a scan mode of another technique is dropped |
| builder | `answer_detect_no_quote.md` | A quote in no source is dropped; the extension decides |
| builder | `answer_llm_failed.md` | A failed detection job (`llm_failed`): the extension decides |
| LLM input | `bundle_17202182.json`, `eln_17202182.yaml`, `T190613_004_header.json` | STM record [17202182](https://zenodo.org/records/17202182) (CC-BY-4.0): header, readme and PDF text |
| LLM input | `bundle_afm.json`, `eln_afm.yaml`, `afm_header.json` | AFM: readme and header; `scan_mode` left to the LLM |
| LLM input | `bundle_without_context.json`, `eln_sts.yaml`, `no_header.json` | STS without context or header |
Expand All @@ -56,7 +57,7 @@ hand-written detection answers.
| LLM input | `eln_instructions_incomplete.md` | A missing section, or one that misses rule values, fails |
| merge | `answer_afm_checks.md` (hand-written) | Each field hits one check; quotes with typographic spaces and hyphens or a missing space are still found |
| merge | `answer_mistral_medium_3_5.md` | Real answer of Mistral Medium 3.5 (LLM Hub, usegalaxy.eu): names made ASCII; a header key alone is no evidence |
| merge | no answer, `answer_skipped.json`, `answer_no_yaml.md` | LLM off, skipped step, unreadable answer: the rule ELN is the output |
| merge | no answer, `answer_skipped.json`, `answer_no_yaml.md`, `answer_llm_failed.md` | LLM off, skipped step, unreadable answer, failed LLM job: the rule ELN is the output |
| merge | `answer_header_json.md` (hand-written), `const_dos_header.json` | Header JSON quotes fill header fields only; a JSON key alone is no evidence |

`eln_17202182.yaml` and `eln_afm.yaml` are rule ELNs: they have no `Sample` part, because the builder
Expand Down
2 changes: 1 addition & 1 deletion tools/nexus_eln/macros.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<macros>
<!-- One plain version for all tools here: they wrap only their own scripts (IUC rule, no
+galaxy part). Raise it with every released change of any of them. -->
<token name="@TOOL_VERSION@">0.4.0</token>
<token name="@TOOL_VERSION@">0.4.1</token>
<token name="@PROFILE@">25.0</token>
<token name="@PYTHON_VERSION@">3.12</token>

Expand Down
12 changes: 11 additions & 1 deletion tools/nexus_eln/nexus_eln_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
from pathlib import Path, PurePosixPath

import yaml
from nexus_eln_llm_merge import allowed_value, Dropped, find_quote, norm, parse_answer
from nexus_eln_llm_merge import (
LLM_FAILED_ANSWER,
allowed_value,
Dropped,
find_quote,
norm,
parse_answer,
)
from nexus_llm_input import plain_text, set_path, source_files

logger = logging.getLogger("nexus_eln_builder")
Expand Down Expand Up @@ -106,6 +113,9 @@ def llm_detection(answer_text, sources, rules):
result = {"status": "no_answer", "fields": {}}
if answer_text is None:
return result
if answer_text.strip() == LLM_FAILED_ANSWER:
result["status"] = "llm_failed"
return result
values, evidence = parse_answer(answer_text)
if values is None:
result["status"] = "unparsable"
Expand Down
18 changes: 18 additions & 0 deletions tools/nexus_eln/nexus_eln_builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@
</assert_contents>
</output>
</test>
<!-- Test 10: the fixed answer the workflow puts in place of a failed detection job. -->
<test expect_num_outputs="2">
<param name="bundle" value="bundle_with_context.json" ftype="json"/>
<param name="rules" value="eln_rules.yaml" ftype="yaml"/>
<param name="header" value="const_dos_header.json" ftype="json"/>
<param name="answer" value="answer_llm_failed.md" ftype="markdown"/>
<output name="eln" ftype="yaml">
<assert_contents>
<has_text text="experiment_technique: STM"/>
</assert_contents>
</output>
<output name="eln_report" ftype="json">
<assert_contents>
<has_json_property_with_value property="status" value="&quot;llm_failed&quot;"/>
<has_json_property_with_value property="experiment_technique" value="&quot;extension .sxm&quot;"/>
</assert_contents>
</output>
</test>
</tests>
<help format="markdown"><![CDATA[
**What it does**
Expand Down
6 changes: 6 additions & 0 deletions tools/nexus_eln/nexus_eln_llm_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

logger = logging.getLogger("nexus_eln_llm_merge")

# The workflow puts this answer (zenodo_nomad_download's `no_answer`) in place of a failed
# llm_hub job. Keep both texts the same.
LLM_FAILED_ANSWER = "LLM job failed: no answer."
NAME_FIELDS = ("Sample.name", "Sample.Sample_component.name")
FORMULA_FIELD = "Sample.Sample_component.chemical_formula"
ELEMENTS = set("""
Expand Down Expand Up @@ -245,6 +248,9 @@ def merge(rule_eln, answer_text, bundle, header, rules, instructions_path):
if answer_text is None:
report["status"] = "no_answer"
return copy.deepcopy(rule_eln), report
if answer_text.strip() == LLM_FAILED_ANSWER:
report["status"] = "llm_failed"
return copy.deepcopy(rule_eln), report
report["answer_sha256"] = hashlib.sha256(answer_text.encode("utf-8")).hexdigest()
if not definition:
report["status"] = "no_definition"
Expand Down
21 changes: 20 additions & 1 deletion tools/nexus_eln/nexus_eln_llm_merge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@
</assert_contents>
</output>
</test>
<!-- Test 07: the fixed answer the workflow puts in place of a failed llm_hub job. -->
<test expect_num_outputs="2">
<param name="bundle" value="bundle_17202182.json" ftype="json"/>
<param name="eln" value="eln_17202182.yaml" ftype="yaml"/>
<expand macro="test_plugin_files"/>
<param name="header" value="T190613_004_header.json" ftype="json"/>
<param name="answer" value="answer_llm_failed.md" ftype="markdown"/>
<output name="merged_eln" ftype="yaml">
<assert_contents>
<not_has_text text="Sample:"/>
</assert_contents>
</output>
<output name="eln_llm_report" ftype="json">
<assert_contents>
<has_json_property_with_value property="status" value="&quot;llm_failed&quot;"/>
</assert_contents>
</output>
</test>
</tests>
<help format="markdown"><![CDATA[
**What it does**
Expand Down Expand Up @@ -208,7 +226,8 @@ evidence:
quote: "beta-Bi2Pd(001) single crystals"
```

An answer that holds only `null` (a skipped step) counts as no answer.
An answer that holds only `null` (a skipped step) counts as no answer. The fixed answer
`LLM job failed: no answer.` (in place of a failed LLM Hub job) gives the status `llm_failed`.

-----

Expand Down
1 change: 1 addition & 0 deletions tools/nexus_eln/test-data/answer_llm_failed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LLM job failed: no answer.
2 changes: 2 additions & 0 deletions tools/zenodo_nomad_download/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ A file that cannot be handled is recorded in the manifest with its reason; the j
`download`). Optional: files already in Galaxy.
- Out: `manifest.json` (`schema_version`, `run_id`, `tool_version`, `archives`, `files`,
`download_failures`), the raw files, one context bundle (JSON) per raw file, and the context files.
Also fixed files the workflow uses in place of a failed job: `no_answer` (LLM Hub), `no_header`
(header) and `no_eln` (ELN builder).
Raw files and bundles share element identifiers (`<record id>-<sha256 prefix>-<file name>`).

## Tests
Expand Down
2 changes: 1 addition & 1 deletion tools/zenodo_nomad_download/macros.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<macros>
<!-- Plain version: the tool wraps only its own script (IUC rule, no +galaxy part).
Raise it with every released change. -->
<token name="@TOOL_VERSION@">0.2.0</token>
<token name="@TOOL_VERSION@">0.3.0</token>
<token name="@PROFILE@">25.0</token>
<token name="@PYTHON_VERSION@">3.12</token>

Expand Down
38 changes: 33 additions & 5 deletions tools/zenodo_nomad_download/zenodo_nomad_download.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#if str($pipeline_version).strip():
--pipeline-version '$pipeline_version'
#end if
## Same text as LLM_FAILED_ANSWER in nexus_eln_llm_merge.py.
&& echo 'LLM job failed: no answer.' > '$no_answer'
## Read as "no header" by nexus_eln (empty `text`, as spm_raw_header writes).
&& echo '{"file": null, "read_with": "no header; the header job failed", "text": ""}' > '$no_header'
## An ELN without a definition: the converter then reports the file as failed.
&& echo '{}' > '$no_eln'
]]></command>
<inputs>
<param name="work_list" type="data" format="json" label="Work list (work_list.json)" help="Written by the NOMAD side: the records and files to download, the limits and the extension lists."/>
Expand All @@ -39,6 +45,11 @@
</inputs>
<outputs>
<data name="manifest" format="json" label="${tool.name} on ${on_string}: Manifest"/>
<!-- The workflow puts this answer in place of a failed LLM Hub job, so the run goes on. -->
<data name="no_answer" format="markdown" label="${tool.name} on ${on_string}: LLM failed answer"/>
<!-- The workflow puts these in place of a failed header or ELN builder job. -->
<data name="no_header" format="json" label="${tool.name} on ${on_string}: No header"/>
<data name="no_eln" format="yaml" label="${tool.name} on ${on_string}: No ELN"/>
<collection name="raw_files" type="list" label="${tool.name} on ${on_string}: Raw files">
<discover_datasets pattern="__designation__" directory="raw_files" format="binary" sort_by="filename"/>
</collection>
Expand All @@ -51,7 +62,7 @@
</outputs>
<tests>
<!-- Test 01: archive with raw, context, junk and known files; unsafe, too large and mismatching files. -->
<test expect_num_outputs="4">
<test expect_num_outputs="7">
<param name="work_list" value="work_list.json" ftype="json"/>
<param name="prefetched">
<collection type="list">
Expand All @@ -78,6 +89,21 @@
<not_has_text text="evil.txt"/>
</assert_contents>
</output>
<output name="no_answer" ftype="markdown">
<assert_contents>
<has_text text="LLM job failed: no answer."/>
</assert_contents>
</output>
<output name="no_header" ftype="json">
<assert_contents>
<has_json_property_with_value property="text" value="&quot;&quot;"/>
</assert_contents>
</output>
<output name="no_eln" ftype="yaml">
<assert_contents>
<has_line line="{}"/>
</assert_contents>
</output>
<!-- Elements are sorted by file name. -->
<output_collection name="raw_files" type="list" count="3">
<element name="17533355-0d16b332fc2e-loose_raw.sxm" file="loose_raw.sxm" ftype="binary"/>
Expand Down Expand Up @@ -106,7 +132,7 @@
<output_collection name="context_files" type="list" count="5"/>
</test>
<!-- Test 02: the zip's index is above the uncompressed limit, so nothing is extracted. -->
<test expect_num_outputs="4">
<test expect_num_outputs="7">
<param name="work_list" value="work_list_uncompressed_limit.json" ftype="json"/>
<param name="prefetched">
<collection type="list">
Expand All @@ -123,7 +149,7 @@
<output_collection name="raw_files" type="list" count="0"/>
</test>
<!-- Test 03: a work list without records gives an empty manifest and empty collections. -->
<test expect_num_outputs="4">
<test expect_num_outputs="7">
<param name="work_list" value="work_list_empty.json" ftype="json"/>
<output name="manifest" ftype="json">
<assert_contents>
Expand All @@ -136,7 +162,7 @@
</test>
<!-- Test 04: context files keep a fixed type, also when Galaxy cannot detect it (binary
bytes in a .csv). A detected type "auto" would stop the report step from scheduling. -->
<test expect_num_outputs="4">
<test expect_num_outputs="7">
<param name="work_list" value="work_list_loose.json" ftype="json"/>
<param name="prefetched">
<collection type="list">
Expand All @@ -160,7 +186,7 @@
<!-- Test 05: PDF text goes into the bundle as pdf_text. A broken PDF and a PDF without a
text layer are only reported in the bundle; their files are still kept. context_sm_page2.pdf: page 2 of the Supplementary
Material of Zenodo record 17202182 (CC-BY-4.0). -->
<test expect_num_outputs="4">
<test expect_num_outputs="7">
<param name="work_list" value="work_list_pdf.json" ftype="json"/>
<param name="prefetched">
<collection type="list">
Expand Down Expand Up @@ -235,6 +261,8 @@ list's limit ("zip bomb"). Archives inside an archive are not extracted.
[pdftotext](https://poppler.freedesktop.org/) into `pdf_text`; a PDF without text (broken,
scanned, too large) gets the reason in `pdf_text_error` and the run goes on.
- **Context files**: the record's context files, for the NOMAD project.
- **LLM failed answer**, **No header**, **No ELN**: fixed files that a workflow can put in place
of a failed LLM Hub, header or ELN builder job, so the run goes on.

Element identifiers are `<record ID>-<first 12 characters of the SHA-256>-<file name>`.
]]></help>
Expand Down
18 changes: 15 additions & 3 deletions workflows/zenodo_harvest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ computes; it writes nothing to NOMAD.
flowchart LR
dl["download + unzip"] --> header["raw file header"] --> detect["technique detection<br/>(LLM, if use llm)"]
detect --> eln["ELN builder"] --> fill["ELN fill<br/>(LLM, if use llm)"] --> merge["check + merge"]
merge --> convert["NeXus converter"] --> report["report builder"]
merge --> convert["NeXus converter"] --> keep["keep success"] --> report["report builder"]
files["ELN files<br/>(once per run)"] --> detect & eln & fill & merge
```

Every step after the download runs once per raw file, except the ELN files step. The technique
comes from the detection answer if its quote is found in the dataset's files, else from the header
Every step after the download runs once per raw file, except the ELN files step.
If a file's job fails, Galaxy pauses its later jobs, and a paused job can stop the whole run.
So the workflow puts a fixed file of the download step in place of a failed or paused job
([`__KEEP_SUCCESS_DATASETS__`](https://galaxyproject.github.io/foundry/patterns/collection-cleanup-after-mapover-failure/)
with a replacement):

- header → "no header";
- LLM (detection or ELN fill) → "LLM job failed", so the file gets its rule ELN;
- ELN builder → an empty ELN, so the converter reports the file as failed.

The *keep success* steps before the report drop a file whose merge or converter job failed, so
the report still runs and lists it as `failed (no_result)`.

The technique comes from the detection answer if its quote is found in the dataset's files, else from the header
markers of the ELN rules, else from the file extension. The LLM part is on by default and can be
turned off; only LLM values with a quote found in the dataset's files are kept.

Expand Down
Loading
Loading