Skip to content

🐛 Switch to nanobind reports leaked instances/types/functions in syrec-editor #530

@TooMuchDakka

Description

@TooMuchDakka

System and Environment Information

  • Windows 10 + MSVC 14.44.35207 as well as Linux Mint with Clang 18.1.3
  • Latest commit from main branch 29ff44e
  • Python 3.12.3

Bug Description

The execution of the syrec-editor executable should not leak any memory when being closed, however in the terminal the following leaks are reported by nanobind:

nanobind: leaked 4 instances!
 - leaked instance 000002225C28D858 of type "mqt.syrec.pysyrec.ConfigurableOptions"
 - leaked instance 000002225C28D948 of type "mqt.syrec.pysyrec.ConfigurableOptions"
 - leaked instance 000002225C28D718 of type "mqt.syrec.pysyrec.ConfigurableOptions"
 - leaked instance 000002225C28D678 of type "mqt.syrec.pysyrec.ConfigurableOptions"
nanobind: leaked 9 types!
 - leaked type "mqt.syrec.pysyrec.NBitValuesContainer"
 - leaked type "QubitLabelType"
 - leaked type "mqt.syrec.pysyrec.AnnotatableQuantumComputation"
 - leaked type "mqt.syrec.pysyrec.ConfigurableOptions"
 - leaked type "mqt.syrec.pysyrec.Program"
 - leaked type "ComparisonKind"
 - leaked type "OpType"
 - leaked type "mqt.core.ir.QuantumComputation"
 - leaked type "IntegerConstantTruncationOperation"
nanobind: leaked 199 functions!
 - leaked function "__repr__"
 - leaked function "cu"
 - leaked function "z"
 - leaked function "swap"
 - leaked function "mcxx_minus_yy"
 - leaked function "line_aware_synthesis"
 - leaked function "from_qasm"
 - leaked function ""
 - leaked function "cryy"
 - leaked function "measure_all"
 - ... skipped remainder
nanobind: this is likely caused by a reference counting issue in the binding code.
See https://nanobind.readthedocs.io/en/latest/refleaks.html

These leaks were not reported when the pybind11 bindings were used but as the referenced nanobind documentation in the terminal output states:

Although leaks aren’t always a serious problem, the decision was made to have nanobind complain noisily about their presence to to encourage early detection and resolution. Other binding tools do not report leaks, allowing them to accumulate unnoticed until they cause serious problems.

So these leaks could have already existed with the pybind11 generated bindings but were simply not reported.

I have assigned both the C++ and python label to this bug since this issue could stem from both the C++ bindings and the python code used to implement the syrec-editor (with some examples that could also apply here again being provided in the nanobind documentation linked in the terminal output). Whether the same issue also applies in the parent mqt-core project was not checked.

Steps to Reproduce

  1. Perform a build from source of mqt.syrec
  2. Launch the installed syrec-editor executable
  3. Close the syrec-editor

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingc++Anything related to C++ codepythonAnything related to Python code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions