Skip to content

馃悰 Contain allocation failures in QDMI device C APIs#2271

Description

@denialhaag

馃 AI text below 馃

System and Environment Information

  • MQT Core: current main and the 3.9 QDMI device implementation
  • QDMI: 1.3.3
  • Language: C++20
  • Platforms: all supported platforms; the issue is independent of the operating system and compiler

Bug Description

Two allocation-capable entry points in the superconducting QDMI provider can let C++ exceptions escape through the C API:

  • MQT_SC_QDMI_device_session_set_parameter calls setDeviceConfigurationParameter, which constructs and assigns strings and filesystem paths.
  • MQT_SC_QDMI_device_session_create_device_job allocates a job and inserts it into an unordered_map.

An allocation failure can therefore throw std::bad_alloc instead of returning QDMI_ERROR_OUTOFMEM. Other unexpected exceptions from an entry point can also cross the C boundary instead of returning QDMI_ERROR_FATAL.

The current QDMI-on-IQM implementation needs the same protection. IQM_QDMI_device_session_set_parameter constructs strings, and IQM_QDMI_device_session_create_device_job uses throwing new without an exception barrier.

QMAP inherited this behavior in its neutral-atom provider and contains it in munich-quantum-toolkit/qmap@4bd4c153. That change makes the allocation-capable methods non-throwing, maps std::bad_alloc to QDMI_ERROR_OUTOFMEM, maps other exceptions to QDMI_ERROR_FATAL, and keeps the output job handle null on failure.

Steps to Reproduce

  1. Allocate a superconducting QDMI device session.
  2. Inject an allocation failure while copying a device configuration parameter, or initialize the session and inject a failure while creating a device job.
  3. Call the corresponding exported device function.
  4. Observe that std::bad_alloc escapes instead of producing a QDMI status code.

The exported C entry points should contain every exception. They should return QDMI_ERROR_OUTOFMEM for allocation failures, return QDMI_ERROR_FATAL for other unexpected failures, and leave output handles in a documented safe state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QDMIAnything related to QDMIbugSomething isn't working

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions