Skip to content

circuit_dict_from_pytket1_dict() fails when circuit contains CustomGate #2049

@cqc-alec

Description

@cqc-alec
from pytket.circuit import CustomGateDef
from sympy import Symbol
from pytket.utils.serialization.migration import circuit_dict_from_pytket1_dict
from pytket import Circuit

a = Symbol("a")
b = Symbol("b")
setup = Circuit(3)
setup.CX(0, 1)
setup.Rz(a + 0.5, 2)
setup.CRz(b, 0, 2)
my_gate = CustomGateDef.define("g", setup, [a, b])
c = Circuit(4)
c.add_custom_gate(my_gate, [0.2, 1.3], [0, 3, 1])
circuit_dict_from_pytket1_dict(c.to_dict())

This fails with KeyError: 'commands'.

The problem is this line, since op["box"]["gate"] is

{'args': ['a', 'b'],
 'definition': {'bits': [],
  'commands': [{'args': [['q', [0]], ['q', [1]]], 'op': {'type': 'CX'}},
   {'args': [['q', [2]]], 'op': {'params': ['0.5 + a'], 'type': 'Rz'}},
   {'args': [['q', [0]], ['q', [2]]], 'op': {'params': ['b'], 'type': 'CRz'}}],
  'created_qubits': [],
  'discarded_qubits': [],
  'implicit_permutation': [[['q', [0]], ['q', [0]]],
   [['q', [1]], ['q', [1]]],
   [['q', [2]], ['q', [2]]]],
  'phase': '0.0',
  'qubits': [['q', [0]], ['q', [1]], ['q', [2]]]},
 'name': 'g'}

which does not have a key called commands.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions