Пример #1
0
def test_create_fake_arg():
    unexpected_kwarg = "create\\(\\) got an unexpected keyword argument 'fake_arg'"
    with pytest.raises(TypeError, match=unexpected_kwarg):
        AwsQuantumJob.create(
            device="device",
            source_module="source",
            fake_arg="fake_value",
        )
Пример #2
0
def test_create_job(
    mock_prepare_quantum_job,
    mock_logs,
    aws_session,
    prepare_job_args,
    quantum_job_arn,
    wait_until_complete,
):
    test_response_args = {"testArgs": "MyTestArg"}
    mock_prepare_quantum_job.return_value = test_response_args
    job = AwsQuantumJob.create(wait_until_complete=wait_until_complete,
                               **prepare_job_args)
    mock_prepare_quantum_job.assert_called_with(**prepare_job_args)
    aws_session.create_job.assert_called_with(**test_response_args)
    if wait_until_complete:
        mock_logs.assert_called_once()
    else:
        mock_logs.assert_not_called()
    assert job.arn == quantum_job_arn
Пример #3
0
from braket.aws import AwsDevice, AwsQuantumJob
from braket.circuits import Circuit
from braket.jobs import save_job_result


def run_job():
    device = AwsDevice(os.environ.get("AMZN_BRAKET_DEVICE_ARN"))

    bell = Circuit().h(0).cnot(0, 1)
    num_tasks = 10
    results = []

    for i in range(num_tasks):
        task = device.run(bell, shots=100)
        result = task.result().measurement_counts
        results.append(result)
        print(f"iter {i}: {result}")

    save_job_result({"results": results})


if __name__ == "__main__":
    job = AwsQuantumJob.create(
        device="arn:aws:braket:::device/quantum-simulator/amazon/sv1",
        source_module="job.py",
        entry_point="job:run_job",
        wait_until_complete=True,
    )
    print(job.result())