Skip to content

Python 3.11 incompatibility: some calls to random.sample() pass a set #887

@mhucka

Description

@mhucka

Using a set in a call to the sample(…) method from the Python random standard library has been deprecated since Python 3.9, and in Python 3.11, it causes an error. This happens in the function util.py:_apply_random_control(…) starting on line 111:

open_qubits = set(all_qubits) - set(gate.qubits)
n_open = min(len(open_qubits), 3)
if n_open == 0:
    # No open qubits to control. Return unmodified gate.
    return gate
control_locs = random.sample(open_qubits, n_open)

There may be other places where it happens, so we should do a sweep through
the code to look for calls to sample().

Metadata

Metadata

Assignees

Labels

area/pythonInvolves Python codeplatform/colabGoogle Colab issues and PRspriority/p1Fix is needed as soon as possible

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions