Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
* Rename Experiment.options to Experiment.experiment_options.
* Add some more comments
  • Loading branch information
chriseclectic committed May 21, 2021
1 parent 1795be8 commit 3e2b180
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
8 changes: 7 additions & 1 deletion qiskit_experiments/base_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@
class BaseAnalysis(ABC):
"""Base Analysis class for analyzing Experiment data.
The data produced by experiments (i.e. subclasses of BaseExperiment)
are analyzed with subclasses of BaseExperiment. The analysis is
typically run after the data has been gathered by the experiment.
For example, an analysis may perform some data processing of the
measured data and a fit to a function to extract a parameter.
When designing Analysis subclasses default values for any kwarg
analysis options of the `run` method should be set by overriding
the `_default_options` class method. When calling `run` these
default values will combined with all other option kwargs in the
default values will be combined with all other option kwargs in the
run method and passed to the `_run_analysis` function.
"""

Expand Down
18 changes: 9 additions & 9 deletions qiskit_experiments/base_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, qubits: Iterable[int], experiment_type: Optional[str] = None)
raise QiskitError("Duplicate qubits in physical qubits list.")

# Experiment options
self._options = self._default_options()
self._experiment_options = self._default_experiment_options()
self._transpile_options = self._default_transpile_options()
self._run_options = self._default_run_options()
self._analysis_options = self._default_analysis_options()
Expand Down Expand Up @@ -194,7 +194,7 @@ def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
# generation

@classmethod
def _default_options(cls) -> Options:
def _default_experiment_options(cls) -> Options:
"""Default kwarg options for experiment"""
# Experiment subclasses should override this method to return
# an `Options` object containing all the supported options for
Expand All @@ -203,11 +203,11 @@ def _default_options(cls) -> Options:
return Options()

@property
def options(self) -> Options:
def experiment_options(self) -> Options:
"""Return the options for the experiment."""
return self._options
return self._experiment_options

def set_options(self, **fields):
def set_experiment_options(self, **fields):
"""Set the experiment options.
Args:
Expand All @@ -217,18 +217,18 @@ def set_options(self, **fields):
AttributeError: If the field passed in is not a supported options
"""
for field in fields:
if not hasattr(self._options, field):
if not hasattr(self._experiment_options, field):
raise AttributeError(
f"Options field {field} is not valid for {type(self).__name__}"
)
self._options.update_options(**fields)
self._experiment_options.update_options(**fields)

@classmethod
def _default_transpile_options(cls) -> Options:
"""Default transpiler options for transpilation of circuits"""
# Experiment subclasses can override this method if they need
# to set specific transpiler options defaults for running the
# experiment.
# to set specific default transpiler options to transpile the
# experiment circuits.
return Options(optimization_level=0)

@property
Expand Down
14 changes: 7 additions & 7 deletions qiskit_experiments/characterization/t1_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class T1Experiment(BaseExperiment):
__analysis_class__ = T1Analysis

@classmethod
def _default_options(cls) -> Options:
def _default_experiment_options(cls) -> Options:
return Options(delays=None, unit="s")

def __init__(
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(
super().__init__([qubit])

# Set experiment options
self.set_options(delays=delays, unit=unit)
self.set_experiment_options(delays=delays, unit=unit)

def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
"""
Expand All @@ -264,30 +264,30 @@ def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
Raises:
AttributeError: if unit is dt but dt parameter is missing in the backend configuration
"""
if self.options.unit == "dt":
if self.experiment_options.unit == "dt":
try:
dt_factor = getattr(backend.configuration(), "dt")
except AttributeError as no_dt:
raise AttributeError("Dt parameter is missing in backend configuration") from no_dt

circuits = []

for delay in self.options.delays:
for delay in self.experiment_options.delays:
circ = QuantumCircuit(1, 1)
circ.x(0)
circ.barrier(0)
circ.delay(delay, 0, self.options.unit)
circ.delay(delay, 0, self.experiment_options.unit)
circ.barrier(0)
circ.measure(0, 0)

circ.metadata = {
"experiment_type": self._type,
"qubit": self.physical_qubits[0],
"xval": delay,
"unit": self.options.unit,
"unit": self.experiment_options.unit,
}

if self.options.unit == "dt":
if self.experiment_options.unit == "dt":
circ.metadata["dt_factor"] = dt_factor

circuits.append(circ)
Expand Down
6 changes: 3 additions & 3 deletions qiskit_experiments/randomized_benchmarking/rb_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
super().__init__(qubits)

# Set configurable options
self.set_options(lengths=list(lengths), num_samples=num_samples)
self.set_experiment_options(lengths=list(lengths), num_samples=num_samples)

# Set fixed options
self._full_sampling = full_sampling
Expand All @@ -85,8 +85,8 @@ def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
A list of :class:`QuantumCircuit`.
"""
circuits = []
for _ in range(self.options.num_samples):
circuits += self._sample_circuits(self.options.lengths, seed=self._rng)
for _ in range(self.experiment_options.num_samples):
circuits += self._sample_circuits(self.experiment_options.lengths, seed=self._rng)
return circuits

def _sample_circuits(
Expand Down

0 comments on commit 3e2b180

Please sign in to comment.