Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable resonator as target device component #387

Closed
9 changes: 6 additions & 3 deletions qiskit_experiments/framework/base_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from collections import OrderedDict
from typing import List, Tuple, Union, Dict

from qiskit_experiments.database_service.device_component import Qubit
from qiskit_experiments.database_service.device_component import Qubit, Resonator
from qiskit_experiments.framework import Options
from qiskit_experiments.framework.store_init_args import StoreInitArgs
from qiskit_experiments.framework.experiment_data import ExperimentData
Expand Down Expand Up @@ -175,12 +175,15 @@ def run_analysis(expdata):

def _get_experiment_components(self, experiment_data: ExperimentData):
"""Subclasses may override this method to specify the experiment components."""
experiment_components = []
if "physical_qubits" in experiment_data.metadata:
experiment_components = [
Qubit(qubit) for qubit in experiment_data.metadata["physical_qubits"]
]
else:
experiment_components = []
if "resonators" in experiment_data.metadata:
experiment_components.extend(
[Resonator(resonator) for resonator in experiment_data.metadata["resonators"]]
)

return experiment_components

Expand Down
20 changes: 17 additions & 3 deletions test/database_service/test_db_analysis_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# pylint: disable=missing-docstring

"""Test AnalysisResult."""
from test.base import QiskitExperimentsTestCase
from unittest import mock
import json

import math
from test.base import QiskitExperimentsTestCase
from test.fake_resonator_experiment import FakeResonatorExperiment
import numpy as np


from qiskit_experiments.test.fake_backend import FakeBackend
from qiskit_experiments.database_service import DbAnalysisResultV1 as DbAnalysisResult
from qiskit_experiments.database_service.device_component import Qubit, Resonator, to_component
from qiskit_experiments.database_service.database_service import DatabaseServiceV1
Expand Down Expand Up @@ -181,3 +181,17 @@ def test_to_component(self):
r1 = to_component("R1")
self.assertIsInstance(r1, Resonator)
self.assertEqual("R1", str(r1))

def test_resonator_experiment(self):
"""Test creating an experiment consisting only resonator components"""
resonator_exp = FakeResonatorExperiment(resonators=[0, 1])
resonator_data = resonator_exp.run(FakeBackend())
resonator_data.block_for_results()
analysis_res = resonator_data._analysis_results
for key in analysis_res._container.keys():
device_components = analysis_res._container[key].device_components
self.assertEqual(len(device_components), 2)
self.assertIsInstance(device_components[0], Resonator)
self.assertEqual("R0", str(device_components[0]))
self.assertIsInstance(device_components[1], Resonator)
self.assertEqual("R1", str(device_components[1]))
59 changes: 59 additions & 0 deletions test/fake_resonator_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Fake experiment using resonator instead of qubits for testing."""

from typing import Iterable, Tuple, List
from qiskit_experiments.framework import BaseExperiment, Options, BaseAnalysis, AnalysisResultData


class FakeResonatorAnalysis(BaseAnalysis):
"""
Simple analysis to test experiment using resonators instead of qubits
"""

# pylint: disable=arguments-differ
def _run_analysis(
self,
experiment_data,
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
return [AnalysisResultData("ResonatorTest", 0)], None


class FakeResonatorExperiment(BaseExperiment):
"""
An experiment to show how to use resonators instead of qubits
"""

__analysis_class__ = FakeResonatorAnalysis

@classmethod
def _default_experiment_options(cls) -> Options:
"""
Add resonators to the experiment options
"""
options = super()._default_experiment_options()
options.resonators = []
return options

def __init__(self, resonators: Iterable[int]):
super().__init__([])

# Set experiment options
self.set_experiment_options(resonators=resonators)

def _additional_metadata(self):
return {"resonators": self.experiment_options.resonators}

def circuits(self):
"""return empty circuits for test"""
return []