Skip to main content
IBM Quantum Platform

Qiskitで外部量子リソースを統合する

Qiskit SDK は、量子リソースの外部プロバイダーを作成するサードパーティをサポートするために構築されている。

つまり、量子コンピューティングリソースを開発または配備するあらゆる組織が、そのサービスをQiskitに統合し、そのユーザーベースを利用することができる。

そのためには、量子計算リソースのリクエストをサポートし、それをユーザーに返すパッケージを作成する必要がある。

さらに、パッケージは、 qiskit.primitives オブジェクトの実装を通して、ユーザーがジョブを投入し、その結果を取得できるようにしなければならない。


バックエンドへのアクセスを提供

ユーザーが外部リソースを使用して QuantumCircuit オブジェクトをトランスパイルおよび実行するには、QPU の接続性や基底ゲート数、量子ビット数などの制約に関する情報を提供する Target このオブジェクトは、接続性、基底ゲート、量子ビット数などのQPUの制約に関する情報を提供します。 これは、ユーザーがQPUのリクエストを行うための QiskitRuntimeService のようなインターフェイスを通じて提供することができる。 このオブジェクトは最低限、 Target を含むべきであるが、より単純なアプローチとしては BackendV2 インスタンスを返すことだろう。

実装例は次のようなものだ:

from qiskit.transpiler import Target
from qsikit.providers import BackendV2

class ProviderService:
    """ Class for interacting with a provider's service"""

    def __init__(
        self,
        #Receive arguments for authentication/instantiation
    ):
        """ Initiate a connection with the provider service, given some method 
                of authentication """

    def return_target(name: Str) -> Target:
        """ Interact with the service and return a Target object """
        return target

    def return_backend(name: Str) -> BackendV2:
        """ Interact with the service and return a BackendV2 object """
        return backend

実行のためのインターフェースを提供

ハードウェア構成を返すサービスのほか、外部のQPUリソースへのアクセスを提供するサービスも、量子ワークロードの実行をサポートする可能性があります。 その機能を公開するには、Qiskitのプリミティブ基底クラスの実装を作成すればよい。例えば BasePrimitiveJob、、、 BaseEstimatorV2 など BaseSamplerV2 がある。 少なくとも、これらのインターフェースは、実行、ジョブステータスの照会、およびジョブ結果の返却を行うためのメソッドを提供できる必要があります。

ジョブのステータスと結果を処理するために、 Qiskit SDK は DataBin, PubResult, PrimitiveResultおよび BasePrimitiveJob オブジェクトを使用しなければならない。

リファレンス実装と同様に、 qiskit.primitives API ドキュメントを参照してください。 BackendEstimatorV2 および BackendSampleV2 を参照のこと。

Estimatorプリミティブの実装例は次のようになる:

from qiskit.primitives import BaseEstimatorV2, BaseSamplerV2, EstimatorPubLike
from qiskit.primitives import DataBin, PubResult, PrimitiveResult, BasePrimitiveJob
from qiskit.providers import BackendV2

class EstimatorImplementation(BaseEstimatorV2):
    """ Class for interacting with the provider's Estimator service """

    def __init__(
        self,
        *,
        backend: BackendV2,
        options: dict
        # Receive other arguments to instantiate an Estimator primitive with the service
    ):
        self._backend = backend
        self._options = options
        self._default_precision = 0.01

    @property
    def backend(self) -> BackendV2:
        """ Return the backend """
        return self._backend

    def run(
        self, pubs: Iterable[EstimatorPubLike], *, precision: float | None = None
    ) -> BasePrimitiveJob[PrimitiveResult[PubResult]]:
    """ Steps to implement: 
            1. Define a default precision if none is given 
            2. Validate pub format
            3. Instantiate an object which inherits from BasePrimitiveJob 
                containing pub and runtime information
            4. Send the job to the execution service of the provider
    """
    job = BasePrimitiveJob(pubs, precision)
    job_with_results = job.submit()
    return job_with_results

そして、サンプラー・プリミティブの実装は次のようになる:

class SamplerImplementation(BaseSamplerV2):
    """ Class for interacting with the provider's Sampler service """

    def __init__(
        self,
        *,
        backend: BackendV2,
        options: dict
        # Receive other arguments to instantiate an Estimator primitive with the service
    ):
        self._backend = backend
        self._options = options
        self._default_shots = 1024

    @property
    def backend(self) -> BackendV2:
        """ Return the Sampler's backend """
        return self._backend

    def run(
        self, pubs: Iterable[SamplerPubLike], *, shots: int | None = None
    ) -> BasePrimitiveJob[PrimitiveResult[SamplerPubResult]]:
    """ Steps to implement: 
            1. Define a default number of shots if none is given 
            2. Validate pub format
            3. Instantiate an object which inherits from BasePrimitiveJob 
                containing pub and runtime information
            4. Send the job to the execution service of the provider
            5. Return the data in some format
    """
    job = BasePrimitiveJob(pubs, shots)
    job_with_results = job.submit()
    return job_with_results
このページは役に立ちましたか?
バグや誤字の報告、またはコンテンツの要求はGitHubで行ってください。