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

pytket to qiskit issue: Mutability of Gates #460

Open
onurdanaci opened this issue Feb 17, 2025 · 2 comments
Open

pytket to qiskit issue: Mutability of Gates #460

onurdanaci opened this issue Feb 17, 2025 · 2 comments
Assignees

Comments

@onurdanaci
Copy link

onurdanaci commented Feb 17, 2025

Hi,

I was using pytket-qiskit package to get circuits between tket and qiskit via qiskit_to_tk and tk_to_qiskit functions. In particular, circuits involving CnZ gates in tket are so convenient, such that I was creating them in tket and transferring to qiskit.

Recently though some updates in tket, qiskit and pytket-qiskit packages created some issues. Some issues are simple, such as the nomenclatura changes from auto_rebases_pass to AutoRebase. But, some are more fundamental. The tk_to_qiskit function, upon encountering circuits involving CnZ gates, now returning the following error:

File [~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/pytket/extensions/qiskit/qiskit_convert.py:1031](http://localhost:8888/lab/workspaces/auto-e/tree/Dropbox/aQa/aQa_codes/Class_H_Learn/shadow_first_hypergraph/pythonProject1/~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/pytket/extensions/qiskit/qiskit_convert.py#line=1030), in tk_to_qiskit(tkcirc, replace_implicit_swaps, perm_warning)
   1028 supported_gate_rebase.apply(tkc)
   1030 for command in tkc:
-> 1031     append_tk_command_to_qiskit(
   1032         command.op, command.args, qcirc, qregmap, cregmap, symb_map, range_preds
   1033     )
   1034 qcirc.global_phase += param_to_qiskit(tkc.phase, symb_map)
   1036 # if UUID stored in name, set parameter uuids accordingly (see qiskit_to_tk)

File [~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/pytket/extensions/qiskit/qiskit_convert.py:886](http://localhost:8888/lab/workspaces/auto-e/tree/Dropbox/aQa/aQa_codes/Class_H_Learn/shadow_first_hypergraph/pythonProject1/~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/pytket/extensions/qiskit/qiskit_convert.py#line=885), in append_tk_command_to_qiskit(op, args, qcirc, qregmap, cregmap, symb_map, range_preds)
    884 if optype == OpType.CnZ:
    885     new_gate = qiskit_gates.ZGate().control(len(qargs) - 1)
--> 886     new_gate.name = "mcz"
    887     return qcirc.append(new_gate, qargs)
    888 if optype == OpType.CnRy:
    889     # might as well do a bit more checking

File [~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/qiskit/circuit/singleton.py:312](http://localhost:8888/lab/workspaces/auto-e/tree/Dropbox/aQa/aQa_codes/Class_H_Learn/shadow_first_hypergraph/pythonProject1/~/.pyenv/versions/jaxqml/lib/python3.12/site-packages/qiskit/circuit/singleton.py#line=311), in _impl_init_subclass.<locals>.__init_subclass__.<locals>._Singleton.__setattr__(self, key, value)
    311 def __setattr__(self, key, value):
--> 312     raise TypeError(
    313         f"This '{self.base_class.__name__}' object is immutable."
    314         " You can get a mutable version by calling 'to_mutable()'."
    315     )

TypeError: This 'CZGate' object is immutable. You can get a mutable version by calling 'to_mutable()'.

I was wondering if you can fix this issue.

Best,
Onur

@cqc-alec
Copy link
Collaborator

Thanks for raising this issue. As it relates to pytket-qiskit I will transfer it to that repo...

@cqc-alec cqc-alec transferred this issue from CQCL/pytket-quantinuum Feb 17, 2025
@CalMacCQ
Copy link
Contributor

CalMacCQ commented Feb 18, 2025

Which version of pytket-qiskit, pytket and qiskit are you using? The following code works fine for the with the latest version of pytket-qiskit (0.63.0) If you could include code to reproduce your issue that would be great.

from pytket import Circuit, OpType
from pytket.extensions.qiskit import tk_to_qiskit

circ = Circuit(4).add_gate(OpType.CnZ, [0, 1, 2, 3])

qc = tk_to_qiskit(circ)

print(qc)

Output

Image

@yao-cqc yao-cqc self-assigned this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants