Exemple #1
0
def test_qasm_output_args_format():
    a = raw_types.NamedQubit('a')
    b = raw_types.NamedQubit('b')
    m_a = common_gates.MeasurementGate('meas_a')(a)
    m_b = common_gates.MeasurementGate('meas_b')(b)
    args = cirq.QasmOutputArgs(precision=4,
                               version='2.0',
                               qubit_id_map={
                                   a: 'aaa[0]',
                                   b: 'bbb[0]'
                               },
                               meas_key_id_map={
                                   'meas_a': 'm_a',
                                   'meas_b': 'm_b'
                               })

    assert args.format('_{0}_', a) == '_aaa[0]_'
    assert args.format('_{0}_', b) == '_bbb[0]_'

    assert args.format('_{0:meas}_', m_a.gate.key) == '_m_a_'
    assert args.format('_{0:meas}_', m_b.gate.key) == '_m_b_'

    assert args.format('_{0}_', 89.1234567) == '_89.1235_'
    assert args.format('_{0}_', 1.23) == '_1.23_'

    assert args.format('_{0:half_turns}_', 89.1234567) == '_pi*89.1235_'
    assert args.format('_{0:half_turns}_', 1.23) == '_pi*1.23_'

    assert args.format('_{0}_', 'other') == '_other_'
Exemple #2
0
def test_on_each():
    class CustomGate(gate_features.SingleQubitGate):
        pass

    a = raw_types.NamedQubit('a')
    b = raw_types.NamedQubit('b')
    c = CustomGate()

    assert c.on_each([]) == []
    assert c.on_each([a]) == [c(a)]
    assert c.on_each([a, b]) == [c(a), c(b)]
    assert c.on_each([b, a]) == [c(b), c(a)]