Beispiel #1
0
def test_observables_join_fail(observables, expected_raises, expected_message):

    with expected_raises as error_info:
        ObservableArray.join(*observables)

    assert (expected_message is None and error_info is None
            or expected_message in str(error_info.value))
Beispiel #2
0
def test_observable_array_join():

    gradient_unit = unit.mole / unit.kilojoule

    observables = [
        ObservableArray(
            value=(numpy.arange(2) + i * 2) * unit.kelvin,
            gradients=[
                ParameterGradient(
                    key=ParameterGradientKey("vdW", "[#6:1]", "epsilon"),
                    value=(numpy.arange(2) + i * 2) * unit.kelvin *
                    gradient_unit,
                )
            ],
        ) for i in range(2)
    ]

    joined = ObservableArray.join(*observables)
    assert len(joined) == 4

    assert numpy.allclose(joined.value,
                          numpy.arange(4).reshape(-1, 1) * unit.kelvin)
    assert numpy.allclose(
        joined.gradients[0].value,
        numpy.arange(4).reshape(-1, 1) * unit.kelvin * gradient_unit,
    )
Beispiel #3
0
def test_observable_array_join_single():

    gradient_unit = unit.mole / unit.kilojoule

    joined = ObservableArray.join(
        ObservableArray(
            value=(numpy.arange(2)) * unit.kelvin,
            gradients=[
                ParameterGradient(
                    key=ParameterGradientKey("vdW", "[#6:1]", "epsilon"),
                    value=(numpy.arange(2)) * unit.kelvin * gradient_unit,
                )
            ],
        ))
    assert len(joined) == 2