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

Unroll circuit_op when validating containment in a gateset #4770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 1 addition & 7 deletions cirq-core/cirq/ops/gateset.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,7 @@ def _validate_operation(self, op: raw_types.Operation) -> bool:
if isinstance(op, raw_types.TaggedOperation):
return self._validate_operation(op.sub_operation)
elif isinstance(op, circuit_operation.CircuitOperation) and self._unroll_circuit_op:
op_circuit = protocols.resolve_parameters(
op.circuit.unfreeze(), op.param_resolver, recursive=False
)
op_circuit = op_circuit.transform_qubits(
lambda q: cast(circuit_operation.CircuitOperation, op).qubit_map.get(q, q)
)
return self.validate(op_circuit)
return self.validate(op.mapped_circuit(deep=True))
else:
return False

Expand Down
7 changes: 7 additions & 0 deletions cirq-core/cirq/ops/gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ def assert_validate_and_contains_consistent(gateset, op_tree, result):
)


def test_gateset_validate_circuit_op_negative_reps():
gate = CustomXPowGate(exponent=0.5)
op = cirq.CircuitOperation(cirq.FrozenCircuit(gate.on(cirq.LineQubit(0))), repetitions=-1)
assert op not in cirq.Gateset(gate)
assert op ** -1 in cirq.Gateset(gate)


def test_with_params():
assert gateset.with_params() is gateset
assert (
Expand Down