Skip to main content
IBM Quantum Platform

집행자 빠른 시작

  • 이 페이지의 코드는 다음 요구 사항을 바탕으로 개발되었습니다. 이 버전 이상을 사용하시기를 권장합니다.

    qiskit[all]~=2.5.2
    qiskit-ibm-runtime~=0.47.0
    samplomatic~=0.21.0
    

Sampler 프리미티브와 마찬가지로, Executor는 양자 회로 실행 시 출력 레지스터를 샘플링하지만, 내장된 오류 억제 또는 완화 기능은 없습니다. 오히려 이는 클라이언트 측에서 설계 의도를 파악할 수 있는 요소를 제공하고, 비용이 많이 드는 회로 변형 생성을 서버 측으로 이전하는 지시형 실행 모델의 일부입니다. 실행기는 회로 주석 및 옵션에 명시된 지침을 따르고, 매개변수 값을 생성 및 바인딩하며, 하드웨어에서 바인딩된 회로를 실행한 후 실행 결과와 메타데이터를 반환합니다. 이 시스템은 사용자를 대신해 암묵적으로 결정을 내리지 않으며, 사용자에게 완전한 통제권과 투명성을 제공합니다.

Note

Qiskit 패키지에는 아직 Executor 기본 객체를 위한 기본 클래스가 없습니다.


시작하기 전에

samplex이 페이지의 일부 코드 예제에서는 Samplomatic 패키지의 일부인 를 사용합니다. 따라서, 해당 코드 블록을 실행하기 전에 다음 코드 블록에 표시된 대로 Samplomatic을 설치해야 합니다. 자세한 내용은 Samplomatic 설명서를 참조하십시오.

pip install samplomatic

# For visualization support, include the visualization dependencies.
# pip install samplomatic[vis]

Executor 기본 객체 사용 방법

1. 계정 초기화

IBM Quantum Compute Service는 관리형 서비스이므로, 먼저 계정을 초기화해야 합니다. 그런 다음 기대값을 계산하는 데 사용할 QPU를 선택할 수 있습니다.

아직 계정이 없다면 ‘ IBM Cloud® 계정 설정’의 단계에 따라 진행해 주세요.

from qiskit_ibm_runtime import QiskitRuntimeService, Executor
from qiskit_ibm_runtime.quantum_program import QuantumProgram
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager
from samplomatic.transpiler import generate_boxing_pass_manager
from samplomatic import build

# Initialize the service and choose a backend
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
print(backend)

Output:

<IBMBackend('ibm_fez')>

2. 회로 생성 및 트랜스파일링

Executor 기본 요소를 사용하려면 최소한 하나의 회로가 필요합니다. 선택적으로 매개변수를 가질 수 있습니다.

# Generate the circuit
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.h(1)
circuit.cz(0, 1)
circuit.h(1)

# Using `measure_all` automatically creates the necessary
# classical registers.
circuit.measure_all()

이 회로는 QPU에서 지원하는 명령어만 사용하도록 변환되어야 합니다(이를 명령어 집합 아키텍처(ISA) 회로라고 합니다). 이를 수행하려면 트랜스파일러를 사용하세요.

# Transpile the circuit
preset_pass_manager = generate_preset_pass_manager(
    backend=backend, optimization_level=0
)
isa_circuit = preset_pass_manager.run(circuit)

3. QuantumProgram 객체를 초기화합니다

작업 부하에 맞춰 를 QuantumProgram 초기화하십시오. QuantumProgramItemsA는 QuantumProgram 로 구성된다. 일반적으로 각 항목은 회로, 일련의 매개변수 값, 그리고 경우에 따라 회로 내용을 무작위화하기 위한 요소로 samplex 구성됩니다. 자세한 내용은 ‘Executor 입력 및 출력’을 참조하십시오.

다음 셀은 를 QuantumProgram 초기화하고 25회의 시뮬레이션을 수행하도록 지정합니다. 다음으로, 트랜스파일링된 대상 회로를 추가합니다.

# Initialize an empty program
program = QuantumProgram(shots=25)

# Append the circuit to the program
program.append_circuit_item(isa_circuit)

4. 선택 사항: 게이트와 측정값을 주석이 달린 상자로 묶기

명령어를 상자에 묶어 주석을 달아주는 것이 의도를 명확히 전달하는 가장 기본적인 방법입니다. 다음 예제에서는 및 그 트위링 매개변수를 사용하여 generate_boxing_pass_manager 2-큐비트 게이트와 측정 연산을 상자로 묶고 트위링 주석을 적용합니다.

# Generate a boxing pass manager to group gates
# and measurements into boxes and add
# a`Twirl` annotation.
boxes_pm = generate_boxing_pass_manager(
    # Add gate twirling
    enable_gates=True,
    # Add measurement twirling
    enable_measures=True,
)

boxed_circuit = boxes_pm.run(isa_circuit)
boxed_circuit.draw("mpl", idle_wires=False)

Output:

Output of the previous code cell

5. 선택 사항: 템플릿 회로와 샘플렉스를 제작하여 프로그램에 추가합니다

다음으로, Samplomatic 빌드 방식을 사용하여 템플릿 회로samplex 쌍을 생성합니다. 이 템플릿 회로는 구조적으로 원래 회로와 동일합니다. 그러나 규정된 주석(이 예에서는 게이트 및 측정 트위링)을 구현하기 위해 단일 큐비트 게이트가 매개변수화 게이트로 대체됩니다. 이 샘플렉스는 템플릿 회로의 무작위 매개변수를 생성하는 데 필요한 모든 정보를 인코딩합니다.

템플릿 회로와 샘플렉스 쌍을 생성한 후, 메서드를 append_samplex_item 사용하여 해당 쌍을 프로그램에 추가하십시오.

및 그 인자에 대한 samplomatic.samplex.Samplex 자세한 내용은 Samplomatic API 문서를 참조하십시오.

# Build the template circuit and the samplex
template_circuit, samplex = build(boxed_circuit)

# Append the template circuit and samplex as a `samplex_item`
program.append_samplex_item(
    template_circuit,
    samplex=samplex,
    shape=(num_randomizations := 20,),
)

6. Executor 호출 및 결과 확인

기본 옵션을 사용하여 프라이머리 Executor (primitive)를 통해 IBM® 백엔드에서 를 QuantumProgram 실행합니다. 사용 가능한 옵션에 대해서는 ‘실행기 옵션’을 참조하십시오.

# Initialize an Executor with the default options
executor = Executor(mode=backend)

# Submit the job
job = executor.run(program)
job

Output:

<RuntimeJobV2('dab7lcrvpcac73ddek40', 'executor')>
# Retrieve the result
result = job.result()

QuantumProgramResult결과는 형입니다. 결과 객체에 대한 자세한 내용은 ‘Executor 입력 및 출력’을 참조하십시오.


다음 단계

권장사항
이 페이지가 도움이 되었습니까?
GitHub에서 버그, 오타를 보고하거나 컨텐츠를 요청하십시오.