Skip to content

Conflict between cudaq and collections.OrderedDict causing AttributeError #2531

@anthonysmaldone

Description

@anthonysmaldone

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

When importing OrderedDict from the collections module in Python, any attempt to define or use a @cudaq.kernel results in an AttributeError. This appears to be a conflict between cudaq and the standard Python library, specifically the collections module. The issue makes it impossible to use OrderedDict alongside cudaq, which could affect projects relying on both.

Steps to reproduce the bug

import cudaq
from collections import OrderedDict

# Define our kernel.
@cudaq.kernel
def kernel(qubit_count: int):
    # Allocate our qubits.
    qvector = cudaq.qvector(qubit_count)
    # Place the first qubit in the superposition state.
    h(qvector[0])
    # Loop through the allocated qubits and apply controlled-X,
    # or CNOT, operations between them.
    for qubit in range(qubit_count - 1):
        x.ctrl(qvector[qubit], qvector[qubit + 1])
    # Measure the qubits.
    mz(qvector)

Expected behavior

The script should execute without errors, as importing OrderedDict from collections is a standard Python operation.

Instead, it fails with the following error:

AttributeError: type object 'collections.OrderedDict' has no attribute '__annotations__'

Is this a regression? If it is, put the last known working version (or commit) here.

No response

Environment

  • CUDA-Q version: 0.9.1 (commit hash a3ab722)
  • Python version: 3.10.16
  • Operating system: HPE Cray OS (SUSE Linux Enterprise Server, SLES)

Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions