Esempio n. 1
0
def test_init_obs_setting():
    q0, q1 = cirq.LineQubit.range(2)
    setting = InitObsSetting(init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1),
                             observable=cirq.X(q0) * cirq.Y(q1))
    assert str(setting) == '+Z(q(0)) * +Z(q(1)) → X(q(0))*Y(q(1))'
    assert eval(repr(setting)) == setting

    with pytest.raises(ValueError):
        setting = InitObsSetting(init_state=cirq.KET_ZERO(q0),
                                 observable=cirq.X(q0) * cirq.Y(q1))
Esempio n. 2
0
def test_observable_to_setting():
    q0, q1, q2 = cirq.LineQubit.range(3)
    observables = [cirq.X(q0) * cirq.Y(q1), cirq.Z(q2) * 1]

    zero_state = cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1) * cirq.KET_ZERO(q2)
    settings_should_be = [
        InitObsSetting(zero_state, observables[0]),
        InitObsSetting(zero_state, observables[1]),
    ]
    assert list(observables_to_settings(observables,
                                        qubits=[q0, q1,
                                                q2])) == settings_should_be
Esempio n. 3
0
def test_measurement_spec_no_symbols():
    q0, q1 = cirq.LineQubit.range(2)
    setting = InitObsSetting(init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1),
                             observable=cirq.X(q0) * cirq.Y(q1))
    meas_spec = _MeasurementSpec(max_setting=setting,
                                 circuit_params={'beta': sympy.Symbol('t')})
    with pytest.raises(ValueError, match='Cannot convert'):
        _ = hash(meas_spec)
Esempio n. 4
0
def test_measurement_spec():
    q0, q1 = cirq.LineQubit.range(2)
    setting = InitObsSetting(init_state=cirq.KET_ZERO(q0) * cirq.KET_ZERO(q1),
                             observable=cirq.X(q0) * cirq.Y(q1))
    meas_spec = _MeasurementSpec(max_setting=setting,
                                 circuit_params={
                                     'beta': 0.123,
                                     'gamma': 0.456
                                 })
    meas_spec2 = _MeasurementSpec(max_setting=setting,
                                  circuit_params={
                                      'beta': 0.123,
                                      'gamma': 0.456
                                  })
    assert hash(meas_spec) == hash(meas_spec2)
    cirq.testing.assert_equivalent_repr(meas_spec)