Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle custom operations with overlapping names in QPY #11646

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Unify uuid logic in version 11
mtreinish committed Jan 31, 2024

Verified

This commit was signed with the committer’s verified signature.
mtreinish Matthew Treinish
commit c88a9a2784eb511e571eae00bd1e81541fcd4ecd
9 changes: 5 additions & 4 deletions qiskit/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
@@ -594,14 +594,15 @@ def _write_instruction(file_obj, instruction, custom_operations, index_map, use_
or isinstance(instruction.operation, library.BlueprintCircuit)
):
gate_class_name = instruction.operation.name
if version >= 11:
# Assign a uuid to each instance of a custom operation
gate_class_name = f"{gate_class_name}_{uuid.uuid4().hex}"
# ucr*_dg gates can have different numbers of parameters,
# the uuid is appended to avoid storing a single definition
# in circuits with multiple ucr*_dg gates.
if instruction.operation.name in {"ucrx_dg", "ucry_dg", "ucrz_dg"}:
elif instruction.operation.name in {"ucrx_dg", "ucry_dg", "ucrz_dg"}:
gate_class_name = f"{gate_class_name}_{uuid.uuid4()}"
elif version >= 11:
# Assign a uuid to each instance of a custom operation
gate_class_name = f"{gate_class_name}_{uuid.uuid4().hex}"

custom_operations[gate_class_name] = instruction.operation
custom_operations_list.append(gate_class_name)