

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 여러 프로그램 실행
<a name="braket-batching-tasks"></a>

Amazon Braket은 여러 양자 프로그램을 효율적으로 실행하기 위한 두 가지 접근 방식, 즉 프로그램 세트와 양자 작업 일괄 처리를 제공합니다.

**프로그램 세트**는 여러 프로그램으로 워크로드를 실행하는 데 선호되는 방법입니다. 이를 통해 여러 프로그램을 단일 Amazon Braket 양자 작업으로 패키징할 수 있습니다. 프로그램 세트는 특히 프로그램 실행 수가 100개에 가까울 때 프로그램을 개별적으로 제출하는 것에 비해 [성능을 개선](https://aws.amazon.com/blogs/quantum-computing/amazon-braket-introduces-program-sets-enabling-customers-to-run-quantum-programs-up-to-24x-faster/)하고 비용을 절감합니다.

현재 IQM 및 Rigetti 디바이스가 프로그램 세트를 지원합니다. 프로그램 세트를 QPU에 제출하기 전에 먼저 [Amazon Braket Local Simulator](https://docs.aws.amazon.com/braket/latest/developerguide/braket-send-to-local-simulator.html)에서 테스트하는 것이 좋습니다. 디바이스가 프로그램 세트를 지원하는지 확인하려면 Amazon Braket SDK를 사용하여 [디바이스의 속성](https://github.com/amazon-braket/amazon-braket-examples/blob/main/examples/braket_features/Getting_Devices_and_Checking_Device_Properties.ipynb)을 보거나 [Amazon Braket 콘솔](https://console.aws.amazon.com/braket/)에서 디바이스 페이지를 볼 수 있습니다.

다음 예제에서는 프로그램 세트를 실행하는 방법을 보여줍니다.

```
from math import pi
from braket.devices import LocalSimulator
from braket.program_sets import ProgramSet
from braket.circuits import Circuit

program_set = ProgramSet([
    Circuit().h(0).cnot(0,1),
    Circuit().rx(0, pi/4).ry(1, pi/8).cnot(1,0),
    Circuit().t(0).t(1).cz(0,1).s(0).cz(1,2).s(1).s(2),
])

device = LocalSimulator()
result = device.run(program_set, shots=300).result()
print(result[0][0].counts)  # The result of the first program in the program set
```

프로그램 세트를 구성하는 다양한 방법(예: 단일 프로그램으로 여러 관찰 가능 항목 또는 파라미터에서 프로그램 세트를 구성) 및 프로그램 세트 결과를 검색하는 방법에 대해 자세히 알아보려면 *Amazon Braket 개발자 안내서*의 [프로그램 세트](https://docs.aws.amazon.com/braket/latest/developerguide/braket-constructing-circuit.html#braket-program-set) 섹션과 Braket 예제 Github 리포지토리의 [프로그램 세트 폴더](https://github.com/amazon-braket/amazon-braket-examples/tree/main/examples/braket_features/program_sets)를 참조하세요.

**양자 작업 일괄 처리**는 모든 Amazon Braket 디바이스에서 사용할 수 있습니다. 일괄 처리는 여러 양자 작업을 병렬로 처리할 수 있으므로 온디맨드 시뮬레이터(SV1, DM1 또는 TN1)에서 실행하는 양자 작업에 특히 유용합니다. 일괄 처리를 사용하면 양자 작업을 병렬로 시작할 수 있습니다. 예를 들어 10개의 양자 작업이 필요하고 해당 양자 작업의 프로그램이 서로 독립적이어야 하는 계산을 수행하려는 경우 작업 일괄 처리를 사용하는 것이 좋습니다. 프로그램 세트를 지원하지 않는 디바이스에서 여러 프로그램으로 워크로드를 실행할 때는 양자 작업 일괄 처리를 사용하십시오.

다음 예제에서는 양자 작업 배체를 실행하는 방법을 보여줍니다.

```
from braket.circuits import Circuit
from braket.devices import LocalSimulator

bell = Circuit().h(0).cnot(0, 1)
circuits = [bell for _ in range(5)]

device = LocalSimulator()
batch = device.run_batch(circuits, shots=100)
print(batch.results()[0].measurement_counts)  # The result of the first quantum task in the batch
```

일괄 처리에 대한 자세한 내용은 GitHub의 [Amazon Braket 예제](https://github.com/amazon-braket/amazon-braket-examples)를 참조하세요.

**Topics**
+ [프로그램 세트 및 비용 정보](#braket-program-sets-costs)
+ [양자 작업 일괄 처리 및 비용 정보](#braket-batching-costs)
+ [양자 작업 일괄 처리 및 PennyLane](#braket-batching-pennylane)
+ [작업 일괄 처리 및 파라미터화된 회로](#braket-batching-parametrized-circuits)

## 프로그램 세트 및 비용 정보
<a name="braket-program-sets-costs"></a>

프로그램 세트는 최대 100개의 프로그램 또는 파라미터 세트를 단일 양자 작업으로 패키징하여 여러 양자 프로그램을 효율적으로 실행합니다. 프로그램 세트를 사용하면 모든 프로그램의 총 샷을 기준으로 작업당 요금과 샷당 요금만 지불하면 되므로 프로그램을 개별적으로 제출하는 것보다 비용이 크게 절감됩니다. 이 접근 방식은 프로그램 수가 많고 프로그램당 샷 수가 적은 워크로드에 특히 유용합니다. 프로그램 세트는 현재 IQM 및 Rigetti 디바이스와 Amazon Braket Local Simulator에서 지원됩니다.

자세한 내용은 [프로그램 세트](https://docs.aws.amazon.com/braket/latest/developerguide/braket-constructing-circuit.html#braket-program-set) 섹션에서 상세한 구현 단계, 모범 사례 및 코드 예제를 참조하세요.

## 양자 작업 일괄 처리 및 비용 정보
<a name="braket-batching-costs"></a>

양자 작업 일괄 처리 및 결제 비용과 관련하여 유의해야 할 몇 가지 주의 사항입니다.
+ 기본적으로, 양자 작업 일괄 처리는 모든 시간 초과 또는 실패 양자 작업을 3회 재시도합니다.
+ SV1의 34qubits와 같이 장기 실행 양자 작업 배치에는 많은 비용이 발생할 수 있습니다. 양자 작업 배치를 시작하기 전에 `run_batch` 할당 값을 주의 깊게 다시 확인해야 합니다. TN1을 `run_batch`와 함께 사용하지 않는 것이 좋습니다.
+  TN1은 실패한 리허설 단계 작업에 대한 비용을 발생시킬 수 있습니다(자세한 내용은 [TN1 description](https://docs.aws.amazon.com/braket/latest/developerguide/braket-devices.html#braket-simulator-tn1) 참조). 자동 재시도는 비용을 증가시킬 수 있으므로 TN1을 사용할 때는 일괄 처리 시 'max\_retries' 수를 0으로 설정하는 것이 좋습니다([Quantum Task Batching, Line 186](https://github.com/aws/amazon-braket-sdk-python/blob/4c7c3b28e5a17b8f0cddf94377b7734fcbe2ebfc/src/braket/aws/aws_quantum_task_batch.py#L186) 참조).

## 양자 작업 일괄 처리 및 PennyLane
<a name="braket-batching-pennylane"></a>

다음 예제와 같이, Amazon Braket에서 PennyLane 사용 시 Amazon Braket 디바이스를 인스턴스화할 때 `parallel = True`을 설정하여 일괄 처리를 활용합니다.

```
import pennylane as qml

# Define the number of wires (qubits) you want to use
wires = 2  # For example, using 2 qubits

# Define your S3 bucket 
my_bucket = "amazon-braket-s3-demo-bucket"
my_prefix = "pennylane-batch-output"
s3_folder = (my_bucket, my_prefix)

device = qml.device("braket.aws.qubit", 
                    device_arn="arn:aws:braket:::device/quantum-simulator/amazon/sv1", 
                    wires=wires, 
                    s3_destination_folder=s3_folder, 
                    parallel=True)
```

PennyLane을 사용한 일괄 처리에 대한 자세한 내용은 [양자 회로의 병렬화된 최적화](https://github.com/aws/amazon-braket-examples/blob/main/examples/pennylane/1_Parallelized_optimization_of_quantum_circuits/1_Parallelized_optimization_of_quantum_circuits.ipynb)를 참조하세요.

## 작업 일괄 처리 및 파라미터화된 회로
<a name="braket-batching-parametrized-circuits"></a>

파라미터화된 회로가 포함된 양자 작업 배치를 제출할 때 배치의 모든 양자 작업에 사용되는 `inputs` 딕셔너리 또는 입력 딕셔너리의 `list`를 제공할 수 있습니다. 이 경우 다음 예제와 같이 `i`번째 딕셔너리가 `i`번째 작업과 쌍을 이룹니다.

```
from braket.circuits import Circuit, FreeParameter, Observable
from braket.aws import AwsQuantumTaskBatch, AwsDevice

# Define your quantum device
device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")

# Create the free parameters
alpha = FreeParameter('alpha')
beta = FreeParameter('beta')

# Create two circuits
circ_a = Circuit().rx(0, alpha).ry(1, alpha).cnot(0, 2).xx(0, 2, beta)
circ_a.variance(observable=Observable.Z(), target=0)

circ_b = Circuit().rx(0, alpha).rz(1, alpha).cnot(0, 2).zz(0, 2, beta)
circ_b.expectation(observable=Observable.Z(), target=2)

# Use the same inputs for both circuits in one batch
tasks = device.run_batch([circ_a, circ_b], inputs={'alpha': 0.1, 'beta': 0.2})

# Or provide each task its own set of inputs
inputs_list = [{'alpha': 0.3, 'beta': 0.1}, {'alpha': 0.1, 'beta': 0.4}]

tasks = device.run_batch([circ_a, circ_b], inputs=inputs_list)
```

단일 파라메트릭 회로에 대한 입력 딕셔너리 목록을 준비하여 양자 작업 배치로 제출할 수도 있습니다. 목록에 N개의 입력 딕셔너리가 있는 경우 배치에는 N개의 양자 작업이 포함됩니다. `i`번째 양자 작업은 `i`번째 입력 딕셔너리로 실행되는 회로에 해당합니다.

```
from braket.circuits import Circuit, FreeParameter

# Create a parametric circuit
circ = Circuit().rx(0, FreeParameter('alpha'))

# Provide a list of inputs to execute with the circuit
inputs_list = [{'alpha': 0.1}, {'alpha': 0.2}, {'alpha': 0.3}]

tasks = device.run_batch(circ, inputs=inputs_list, shots=100)
```