def test_run_annealing():
    sim = LocalSimulator(DummyAnnealingSimulator())
    task = sim.run(Problem(ProblemType.ISING))
    assert task.result() == AnnealingQuantumTaskResult.from_object(
        ANNEALING_RESULT)
def test_run_annealing_unsupported():
    sim = LocalSimulator(DummyCircuitSimulator())
    sim.run(Problem(ProblemType.ISING))
def test_qpu_tracking():
    problem = Problem(ProblemType("QUBO"),
                      linear={35: 1},
                      quadratic={(35, 36): -1})
    device = AwsDevice("arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6")
    other_device = AwsDevice(
        "arn:aws:braket:us-west-2::device/qpu/d-wave/Advantage_system6")

    device.run(problem, shots=50).result()
    with Tracker() as t:
        device.run(problem, shots=100).result()
        other_device.run(problem, shots=400).result()
        t_partial_cost = t.qpu_tasks_cost()
        assert t_partial_cost > 0
        with Tracker() as s:
            task = device.run(problem, shots=200)
            assert s.quantum_tasks_statistics() == {
                "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6": {
                    "shots": 200,
                    "tasks": {
                        "CREATED": 1
                    },
                }
            }
            task.result()

    assert s.simulator_tasks_cost() == 0
    assert t.simulator_tasks_cost() == 0

    assert s.quantum_tasks_statistics() == {
        "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6": {
            "shots": 200,
            "tasks": {
                "COMPLETED": 1
            }
        }
    }
    assert t.quantum_tasks_statistics() == {
        "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6": {
            "shots": 300,
            "tasks": {
                "COMPLETED": 2
            }
        },
        "arn:aws:braket:us-west-2::device/qpu/d-wave/Advantage_system6": {
            "shots": 400,
            "tasks": {
                "COMPLETED": 1
            },
        },
    }

    assert s.qpu_tasks_cost() > 0
    assert t.qpu_tasks_cost() > s.qpu_tasks_cost()
    assert t.qpu_tasks_cost() > t_partial_cost

    circuit = Circuit().h(0)
    with Tracker() as t:
        AwsDevice("arn:aws:braket:::device/qpu/ionq/ionQdevice").run(circuit,
                                                                     shots=10)
        AwsDevice("arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy").run(
            circuit, shots=10)
        AwsDevice(
            "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2").run(
                circuit, shots=10)

    assert t.qpu_tasks_cost() > 0