def test_with_key_path_prefix(): a = cirq.LineQubit(0) op = cirq.measure(a, key='m') remap_op = cirq.with_key_path_prefix(op, ('a', 'b')) assert cirq.measurement_key_names(remap_op) == {'a:b:m'} assert cirq.with_key_path_prefix(remap_op, tuple()) is remap_op assert cirq.with_key_path_prefix(op, tuple()) is op assert cirq.with_key_path_prefix(cirq.X(a), ('a', 'b')) is NotImplemented
def test_with_key_path_prefix(): a, b, c = cirq.LineQubit.range(3) m = cirq.Moment(cirq.measure(a, key='m1'), cirq.measure(b, key='m2'), cirq.X(c)) mb = cirq.with_key_path_prefix(m, ('b', )) mab = cirq.with_key_path_prefix(mb, ('a', )) assert mab.operations[0] == cirq.measure( a, key=cirq.MeasurementKey.parse_serialized('a:b:m1')) assert mab.operations[1] == cirq.measure( b, key=cirq.MeasurementKey.parse_serialized('a:b:m2')) assert mab.operations[2] is m.operations[2]
def test_keys_under_parent_path(): a = cirq.LineQubit(0) op1 = cirq.CircuitOperation(cirq.FrozenCircuit(cirq.measure(a, key='A'))) assert cirq.measurement_key_names(op1) == {'A'} op2 = op1.with_key_path(('B',)) assert cirq.measurement_key_names(op2) == {'B:A'} op3 = cirq.with_key_path_prefix(op2, ('C',)) assert cirq.measurement_key_names(op3) == {'C:B:A'} op4 = op3.repeat(2) assert cirq.measurement_key_names(op4) == {'C:B:0:A', 'C:B:1:A'}
def test_sympy_path_prefix(): q = cirq.LineQubit(0) op = cirq.X(q).with_classical_controls(sympy.Symbol('b')) prefixed = cirq.with_key_path_prefix(op, ('0', )) assert cirq.control_keys(prefixed) == {'0:b'}