Beispiel #1
0
def _(problem: Problem, simulator: BraketSimulator, shots, *args, **kwargs):
    if DeviceActionType.ANNEALING not in simulator.properties.action:
        raise NotImplementedError(
            f"{type(simulator)} does not support quantum annealing problems")
    ir = problem.to_ir()
    results = simulator.run(ir, shots, *args, *kwargs)
    return AnnealingQuantumTaskResult.from_object(results)
Beispiel #2
0
def test_from_object(
    result_str_1,
    solutions,
    values,
    solution_counts,
    variable_count,
    problem_type,
    task_metadata,
    additional_metadata,
):
    result = AnnealingQuantumTaskResult.from_object(
        AnnealingTaskResult.parse_raw(result_str_1))
    solutions = np.asarray(solutions, dtype=int)
    values = np.asarray(values, dtype=float)
    solution_counts = np.asarray(solution_counts, dtype=int)
    assert result.variable_count == variable_count
    assert result.problem_type == problem_type
    assert result.task_metadata == task_metadata
    assert result.additional_metadata == additional_metadata
    np.testing.assert_equal(
        result.record_array,
        AnnealingQuantumTaskResult._create_record_array(
            solutions, solution_counts, values),
    )
Beispiel #3
0
def test_from_object_equal_to_from_string(result_str_1):
    assert AnnealingQuantumTaskResult.from_object(
        AnnealingTaskResult.parse_raw(result_str_1)
    ) == AnnealingQuantumTaskResult.from_string(result_str_1)
Beispiel #4
0
def _(result: AnnealingTaskResult) -> AnnealingQuantumTaskResult:
    return AnnealingQuantumTaskResult.from_object(result)
def test_run_annealing():
    sim = LocalSimulator(DummyAnnealingSimulator())
    task = sim.run(Problem(ProblemType.ISING))
    assert task.result() == AnnealingQuantumTaskResult.from_object(
        ANNEALING_RESULT)