Ejemplo n.º 1
0
def test_sum_expectation_values_with_covariances():
    values = np.array([5, -2, 1])
    correlations = [np.array([[1, 0.5], [0.5, 2]]), np.array([[7]])]
    covariances = [correlations[0] / 10, correlations[1] / 10]
    expectation_values = ExpectationValues(values, correlations, covariances)
    total = sum_expectation_values(expectation_values)
    assert np.isclose(total.value, 4)
    assert np.isclose(total.precision, np.sqrt((1 + 0.5 + 0.5 + 2 + 7) / 10))
Ejemplo n.º 2
0
def get_summed_expectation_values(
        operator: str,
        measurements: str,
        use_bessel_correction: Optional[bool] = True):
    if isinstance(operator, str):
        operator = load_qubit_operator(operator)
        operator = change_operator_type(operator, openfermion.IsingOperator)
    if isinstance(measurements, str):
        measurements = Measurements.load_from_file(measurements)
    expectation_values = measurements.get_expectation_values(
        operator, use_bessel_correction=use_bessel_correction)
    value_estimate = sum_expectation_values(expectation_values)
    save_value_estimate(value_estimate, "value-estimate.json")
Ejemplo n.º 3
0
 def test_sum_expectation_values(self):
     expectation_values = ExpectationValues(np.array([5, -2, 1]))
     total = sum_expectation_values(expectation_values)
     assert np.isclose(total.value, 4)
     assert total.precision is None