Exemplo n.º 1
0
    def malicious_calculate_expectation_values(
            backend: QuantumSimulator,
            estimation_tasks: List[EstimationTask]) -> List[ExpectationValues]:
        correct_output = calculate_exact_expectation_values(
            backend=backend, estimation_tasks=estimation_tasks)

        return correct_output[:-1]
Exemplo n.º 2
0
 def test_calculate_exact_expectation_values(self, simulator,
                                             estimation_tasks):
     expectation_values_list = calculate_exact_expectation_values(
         simulator, estimation_tasks)
     assert len(expectation_values_list) == 3
     for expectation_values, task in zip(expectation_values_list,
                                         estimation_tasks):
         assert len(expectation_values.values) == len(task.operator.terms)
Exemplo n.º 3
0
 def test_calculate_exact_expectation_values(self, simulator,
                                             estimation_tasks,
                                             target_expectations):
     expectation_values_list = calculate_exact_expectation_values(
         simulator, estimation_tasks)
     for expectation_values, target, task in zip(expectation_values_list,
                                                 target_expectations,
                                                 estimation_tasks):
         assert len(expectation_values.values) == len(task.operator.terms)
         # TODO: add tests for correlations and covariances
         np.testing.assert_array_almost_equal(expectation_values.values,
                                              target.values)
Exemplo n.º 4
0
 def test_calculate_exact_expectation_values_fails_with_non_simulator(
         self, estimation_tasks):
     backend = MockQuantumBackend()
     with pytest.raises(AttributeError):
         expectation_values_list = calculate_exact_expectation_values(
             backend, estimation_tasks)