Skip to content

Commit

Permalink
Call decompose_once in TaggedOperation (quantumlib#5071)
Browse files Browse the repository at this point in the history
* Call decompose_once in TaggedOperation

* Rename test function

* Maybe more robust decomposition
  • Loading branch information
tonybruguier authored and rht committed May 1, 2023
1 parent 6c68b17 commit 93df744
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def _json_dict_(self) -> Dict[str, Any]:
return protocols.obj_to_dict_helper(self, ['sub_operation', 'tags'])

def _decompose_(self) -> 'cirq.OP_TREE':
return protocols.decompose(self.sub_operation)
return protocols.decompose_once(self.sub_operation, default=None)

def _pauli_expansion_(self) -> value.LinearDict[str]:
return protocols.pauli_expansion(self.sub_operation)
Expand Down
16 changes: 16 additions & 0 deletions cirq-core/cirq/protocols/decompose_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,19 @@ def x_to_hzh(op: 'cirq.Operation'):
cirq.measure(a, b, key='m'),
)
assert actual == expected


def test_decompose_tagged_operation():
op = cirq.TaggedOperation(
cirq.CircuitOperation(
circuit=cirq.FrozenCircuit(
[
cirq.Moment(
cirq.SWAP(cirq.LineQubit(0), cirq.LineQubit(1)),
),
]
),
),
'tag',
)
assert cirq.decompose_once(op) == cirq.decompose_once(op.untagged)

0 comments on commit 93df744

Please sign in to comment.