Skip to main content

hep-llm-helpers

Small reusable helpers for HEP analysis code generated with large language models.

Install

python -m pip install hep-llm-helpers

The xAOD helper module is imported as:

from hep_llm_helpers.xaod_hints import make_a_tool, make_tool_accessor

xAOD tool example

make_a_tool adds the C++ tool initialization metadata to a func_adl query and returns a ToolInfo handle. Pass that handle to make_tool_accessor to expose a tool operation as a Python function that can be used inside a query. The accessor's source_code is C++ and must assign its result to the variable named result.

Here is a complete ATLAS PHYSLITE b-tagging example. It configures the BTaggingSelectionTool at the FixedCutBEff_77 operating point and returns both a tag decision and a tag weight:

from func_adl_servicex_xaodr25 import FuncADLQueryPHYSLITE
from func_adl_servicex_xaodr25.xAOD.jet_v1 import Jet_v1

from hep_llm_helpers.xaod_hints import make_a_tool, make_tool_accessor

base_query = FuncADLQueryPHYSLITE()

# The tool name must be unique if a query uses more than one tool instance.
query_with_tool, tag_tool = make_a_tool(
    base_query,
    tool_name="btag_tool",
    tool_type="BTaggingSelectionTool",
    include_files=["xAODBTaggingEfficiency/BTaggingSelectionTool.h"],
    link_libraries=["xAODBTaggingEfficiencyLib"],
    init_lines=[
        'ANA_CHECK(asg::setProperty({tool_name}, "OperatingPoint", "FixedCutBEff_77"));',
        "ANA_CHECK({tool_name}->initialize());",
    ],
)

jet_is_tagged = make_tool_accessor(
    tag_tool,
    function_name="jet_is_tagged",
    source_code=[
        "result = static_cast<bool>({tool_name}->accept(*jet));",
    ],
    arguments=[("jet", Jet_v1)],
    return_type_cpp="bool",
    return_type_python="bool",
)

tag_weight = make_tool_accessor(
    tag_tool,
    function_name="tag_weight",
    source_code=[
        "ANA_CHECK({tool_name}->getTaggerWeight(*jet, result, false));",
    ],
    arguments=[("jet", Jet_v1)],
    return_type_cpp="double",
    return_type_python="float",
)

# Continue building the query from query_with_tool, not base_query, so the
# injected tool metadata is retained during ServiceX translation.
query = query_with_tool.Select(
    lambda event: {
        "jet_is_tagged": event.Jets().Select(lambda jet: jet_is_tagged(jet)),
        "tag_weight": event.Jets().Select(lambda jet: tag_weight(jet)),
    }
)

The same pattern applies to other xAOD tools: initialize the tool once with make_a_tool, create one or more accessors from its ToolInfo, and call those accessors only in the query derived from the returned query object. Use a different tool_name for each independently configured tool instance.

Development

This project uses Hatch:

hatch run test:run
hatch build

The local Hatch environments derive a development version from Git automatically. A release build derives the package version from the GitHub release tag.

Releases

Create a draft GitHub release with a tag such as v0.1.0, then publish the release. The release.yml workflow builds the distributions and publishes them to PyPI using GitHub OIDC trusted publishing. The repository must have a protected pypi environment and a matching PyPI trusted publisher configuration before the first release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hep_llm_helpers-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hep_llm_helpers-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file hep_llm_helpers-1.0.0.tar.gz.

File metadata

  • Download URL: hep_llm_helpers-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for hep_llm_helpers-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb6adc4ef09276fd86763a5fc1935da369b9b65a9674b7f48eed72efe8f4ffbb
MD5 1f1393ed1bad528562a533a92a3789a6
BLAKE2b-256 da00e7b92ba8abd95fb34232df5ae8ac7fc9ccdf569401bf9347d72301de310e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hep_llm_helpers-1.0.0.tar.gz:

Publisher: release.yml on iris-hep/hep-llm-helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hep_llm_helpers-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hep_llm_helpers-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77c035e751e7c79c155a4c39bad378bb7eecd914a7ee63a5501fb1e8f5576022
MD5 4217949f372147c96e6a2988c8cb607c
BLAKE2b-256 39cfa66988b7205b8074133a8f65bd69979f39c1fcc2490f0b4c1340d382e654

See more details on using hashes here.

Provenance

The following attestation bundles were made for hep_llm_helpers-1.0.0-py3-none-any.whl:

Publisher: release.yml on iris-hep/hep-llm-helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page