Skip to content

Example on how to call Circuit.rename_units #492

@jvdwetering

Description

@jvdwetering

I'm trying to change register names in a pytket circuit so that I can save to qasm. It tells me I should call rename_units to do that, I however can't figure out how I should actually call this.

TypeError: rename_units(): incompatible function arguments. The following argument types are supported:
    1. rename_units(self, map: collections.abc.Mapping[pytket._tket.unit_id.UnitID | pytket._tket.unit_id.Qubit | pytket._tket.unit_id.Bit, pytket._tket.unit_id.UnitID | pytket._tket.unit_id.Qubit | pytket._tket.unit_id.Bit]) -> bool

Invoked with types: pytket._tket.circuit.Circuit, dict

What should this mapping be? Should it map from these types to strings? Or to something else? Can I give it a dict that only renames some of the units, or must it contain everything? And shouldn't there be a corresponding method get_units() so you can just take that output and modify it?

Here's what I tried:

a = circ.get_q_register("a[q[0]]")
l = a.to_list()
d = {q: f"f{i}" for i, q in enumerate(l)}
circ.rename_units(d)

Looks like if I call it with {q:q} then it doesn't fail, but it obviously doesn't change anything. I can't however change the name in the qubits because they don't have setters, so I'm not sure how I'm supposed to change the name in these registers in these cases.

Metadata

Metadata

Assignees

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