Skip to main content
IBM Quantum Platform

빠른 시작

이 가이드에서는 해당 qiskit-addon-obp 패키지의 최소 실행 가능한 예제를 보여줍니다. 우리는 연산자 역전파(OBP)를 사용하여 후행 게이트를 관측량에 통합함으로써 양자 회로의 깊이를 줄입니다.

기대값 O=ψUOUψ\langle O \rangle = \langle \psi | U^\dagger O U | \psi \rangle 은 회로 UU 에서 뒤쪽의 게이트 블록을 떼어내고, 이를 이용해 고전적으로 관측량을 공액 변환하더라도 변하지 않는다. OBP는 이 과정을 반복적으로 적용하여, 회로 클래스의 일부를 고전적인 방식으로 평가함으로써 하드웨어에서는 더 단순한 회로만 실행되도록 합니다. 그 대가로, 흡수된 각 게이트는 관측량을 더 많은 파울리 항으로 확장시킬 수 있으므로, 절약된 깊이와 관측량의 증가를 저울질해야 한다.

이 도구를 사용하여 현실적인 워크플로를 구축하고 양자 하드웨어에서 실행하는 방법에 대한 예시를 보려면, ‘ IBM Quantum Platform ( OBP 튜토리얼 )’의 튜토리얼을 확인해 보세요.


OBP에 필요한 입력 자료를 준비하십시오

OBP는 회로 슬라이스 목록과 관측 가능한 변수를 입력으로 받습니다. 이는 회로의 끝부분에서부터 관측량 쪽으로 슬라이스를 하나씩 역전파함으로써, 관측량에 추가적인 파울리 항이 발생하는 대가로 회로의 깊이를 줄입니다. 여기서는 10-큐비트 하이젠베르크 모델에 대한 시간 진화 회로를 생성하고, 게이트 유형별로 분할합니다.

아래에서는 원래 회로를 그린 다음, 슬라이스 경계를 표시하는 장벽을 추가하여 재구성된 동일한 회로를 보여줍니다. 각 슬라이스는 단일 역전파 단계에서 관측 가능량으로 흡수될 수 있는 단위입니다.

import numpy as np
from qiskit.quantum_info import SparsePauliOp
from qiskit.synthesis import LieTrotter
from qiskit.transpiler import CouplingMap
from qiskit_addon_utils.problem_generators import (
    generate_time_evolution_circuit,
    generate_xyz_hamiltonian,
)
from qiskit_addon_utils.slicing import combine_slices, slice_by_gate_types

# Generate a circuit to reduce
coupling_map = CouplingMap.from_heavy_hex(3, bidirectional=False)
reduced_coupling_map = coupling_map.reduce(
    [0, 13, 1, 14, 10, 16, 5, 12, 8, 18]
)

hamiltonian = generate_xyz_hamiltonian(
    reduced_coupling_map,
    coupling_constants=(np.pi / 8, np.pi / 4, np.pi / 2),
    ext_magnetic_field=(np.pi / 3, np.pi / 6, np.pi / 9),
)

circuit = generate_time_evolution_circuit(
    hamiltonian,
    time=0.2,
    synthesis=LieTrotter(reps=2),
)

# Slice the circuit and define an observable
slices = slice_by_gate_types(circuit)
observable = SparsePauliOp("IIIIIIIIIZ")

print(f"Original circuit depth: {circuit.depth()}")
print(f"Number of slices: {len(slices)}")
print(f"Observable terms: {len(observable)}")

Output:

Original circuit depth: 18
Number of slices: 18
Observable terms: 1
# Recombine the slices with barriers to make the slice boundaries visible
sliced_circuit = combine_slices(slices, include_barriers=True)

print("Original circuit:")
display(circuit.draw("mpl", scale=0.6, fold=-1))
print("Sliced circuit (recombined with barriers for visualization)")
sliced_circuit.draw("mpl", scale=0.6, fold=-1)

Output:

Original circuit:
Output of the previous code cell
Sliced circuit (recombined with barriers for visualization)
Output of the previous code cell

OBP를 사용하여 회로 두께를 줄이세요

슬라이스를 관측 가능 객체에 흡수하기 위해 backpropagate 를 호출합니다. 이 함수는 확장된 관측 가능 객체, 전파되지 않은 회로 슬라이스, 그리고 해당 절차에 대한 메타데이터를 반환합니다.

방치할 경우, 관측량은 2n2^n 파울리 항 쪽으로 증가할 수 있다. 이러한 성장은 다음과 같이 operator_budget 상한이 정해집니다. 여기서는 큐비트 단위로 공통하는 군을 최대 8개까지 허용하며, 이는 QPU에서 관측량을 평가하는 데 필요한 시도의 횟수를 대략적으로 결정합니다. 다음 슬라이스를 흡수하는 데 소요되는 비용이 예산을 초과하는 즉시 역전파가 중단되는데, 바로 아래에서 그런 일이 발생합니다. 관측 가능한 값이 8개의 통근 그룹을 모두 채우기 전에 18개의 슬라이스 중 7개만 흡수된 후 절차가 중단됩니다.

회로를 더 깊이 파고들기 위해, 에 대한 키워드 truncation_error_budget 인자를 사용하여 관측량이 커짐에 따라 계수가 작은 파울리 항을 제거할 수 backpropagate 있다. 이는 잘려나가는 파울리 항의 크기에 비례하는 오차를 대가로, 관측량의 증가를 억제합니다. 이 두 가지 예산은 상호 보완적이며 함께 사용할 수 있습니다. 하나는 관측값의 크기를 조절하고 operator_budget , 다른 하나는 항을 생략함으로써 발생하는 오차를 truncation_error_budget 조절합니다.

from qiskit_addon_obp import backpropagate
from qiskit_addon_obp.utils.simplify import OperatorBudget

max_qwc_groups = 8
bp_obs, remaining_slices, metadata = backpropagate(
    observable,
    slices,
    operator_budget=OperatorBudget(max_qwc_groups=max_qwc_groups),
)

reduced_circuit = combine_slices(remaining_slices)
num_groups = len(bp_obs.group_commuting(qubit_wise=True))

print(
    f"Backpropagated {metadata.num_backpropagated_slices} of {len(slices)} slices."
)
print(
    f"Reduced circuit depth: {reduced_circuit.depth()} (was {circuit.depth()})"
)
print(f"Observable grew from {len(observable)} to {len(bp_obs)} Pauli terms.")
print(
    f"Filled {num_groups} of {max_qwc_groups} commuting groups, exhausting the budget."
)

Output:

Backpropagated 7 of 18 slices.
Reduced circuit depth: 11 (was 18)
Observable grew from 1 to 18 Pauli terms.
Filled 8 of 8 commuting groups, exhausting the budget.
reduced_circuit.draw("mpl", scale=0.6, fold=-1)

Output:

Output of the previous code cell
이 페이지가 도움이 되었습니까?
GitHub에서 버그, 오타를 보고하거나 컨텐츠를 요청하십시오.