Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
#7 Add get_example_ibm_runtime_estimator_qnn
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk0629 committed Oct 18, 2024
1 parent e78647b commit c4f30c9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/qnn_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import yaml

import qiskit
import qiskit_aer
import qiskit_aer.primitives
import qiskit_ibm_runtime
from qiskit_machine_learning.neural_networks import EstimatorQNN

from src.quant_conv_layer import QuantConvLayer
Expand Down Expand Up @@ -53,6 +56,26 @@ def get_example_noisy_aer_estimator_qnn(

return self.get_example_structure_estimator_qnn(8, noisy_estimator)

def get_example_ibm_runtime_estimator_qnn(self, config_path: str) -> EstimatorQNN:
"""Get the EstimatorWNN introduced in the qiskit example with a real ibm quantum hardware.
:param str config_path: path to config file including my ibm quantum token
:return EstimatorQNN: EstimatorQNN introduced in qiskit example with real ibm quantum hardware
"""
# Read my ibm quantum token.
with open(config_path, "r") as yaml_file:
config = yaml.safe_load(yaml_file)
ibm_quantum_token = config["my_ibm_quantum_token"]

# Get the estimator being able to access to a real hardware.
service = qiskit_ibm_runtime.QiskitRuntimeService(
channel="ibm_quantum", token=ibm_quantum_token
)
backend = service.least_busy(operational=True, simulator=False)
real_hardware_estimator = qiskit_ibm_runtime.Estimator(mode=backend)

return self.get_example_structure_estimator_qnn(8, real_hardware_estimator)

def get_example_structure_estimator_qnn(
self, data_size: int, estimator: None | qiskit.primitives.BaseEstimator = None
) -> EstimatorQNN:
Expand Down

0 comments on commit c4f30c9

Please sign in to comment.