munich-quantum-toolkit / munich-quantum-toolkit/core

🐛 Contain allocation failures in QDMI device C APIs

Open
#2,271 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug QDMI
Dominant language
C++
Stars
133
Forks
73
Avg merge
17h 34m
Merged PRs (30d)
261

Description

🤖 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the superconducting and IQM provider implementations of MQT_SC_QDMI_device_session_set_parameter, MQT_SC_QDMI_device_session_create_device_job, and their IQM counterparts. Compare their exception handling with the referenced QMAP commit, then verify that allocation failures return QDMI_ERROR_OUTOFMEM, unexpected exceptions return QDMI_ERROR_FATAL, and output job handles remain null on failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.