munich-quantum-toolkit / munich-quantum-toolkit/core
🐛 Contain allocation failures in QDMI device C APIs
Nobody has claimed this yet.
- 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
mainand 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_parametercallssetDeviceConfigurationParameter, which constructs and assigns strings and filesystem paths.MQT_SC_QDMI_device_session_create_device_joballocates a job and inserts it into anunordered_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
- Allocate a superconducting QDMI device session.
- Inject an allocation failure while copying a device configuration parameter, or initialize the session and inject a failure while creating a device job.
- Call the corresponding exported device function.
- Observe that
std::bad_allocescapes 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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