|
13 | 13 | Base Experiment class.
|
14 | 14 | """
|
15 | 15 |
|
16 |
| -from abc import ABC, abstractmethod |
17 | 16 | import copy
|
| 17 | +from abc import ABC, abstractmethod |
18 | 18 | from collections import OrderedDict
|
19 | 19 | from typing import Sequence, Optional, Tuple, List, Dict, Union
|
20 | 20 |
|
21 |
| -from qiskit import transpile, QuantumCircuit |
| 21 | +from qiskit import QuantumCircuit |
22 | 22 | from qiskit.providers import Job, Backend
|
23 | 23 | from qiskit.exceptions import QiskitError
|
24 | 24 | from qiskit.qobj.utils import MeasLevel
|
25 | 25 | from qiskit.providers.options import Options
|
26 | 26 | from qiskit_experiments.framework import BackendData
|
27 | 27 | from qiskit_experiments.framework.store_init_args import StoreInitArgs
|
| 28 | +from qiskit_experiments.framework.transpilation import ( |
| 29 | + DEFAULT_TRANSPILE_OPTIONS, |
| 30 | + map_qubits, |
| 31 | + minimal_transpile, |
| 32 | +) |
28 | 33 | from qiskit_experiments.framework.base_analysis import BaseAnalysis
|
29 | 34 | from qiskit_experiments.framework.experiment_data import ExperimentData
|
30 | 35 | from qiskit_experiments.framework.configs import ExperimentConfig
|
@@ -373,9 +378,8 @@ def _transpiled_circuits(self) -> List[QuantumCircuit]:
|
373 | 378 |
|
374 | 379 | This function can be overridden to define custom transpilation.
|
375 | 380 | """
|
376 |
| - transpile_opts = copy.copy(self.transpile_options.__dict__) |
377 |
| - transpile_opts["initial_layout"] = list(self.physical_qubits) |
378 |
| - transpiled = transpile(self.circuits(), self.backend, **transpile_opts) |
| 381 | + circuits = [map_qubits(c, self.physical_qubits) for c in self.circuits()] |
| 382 | + transpiled = minimal_transpile(circuits, self.backend, self.transpile_options) |
379 | 383 |
|
380 | 384 | return transpiled
|
381 | 385 |
|
@@ -418,11 +422,36 @@ def set_experiment_options(self, **fields):
|
418 | 422 |
|
419 | 423 | @classmethod
|
420 | 424 | def _default_transpile_options(cls) -> Options:
|
421 |
| - """Default transpiler options for transpilation of circuits""" |
| 425 | + """Default transpiler options for transpilation of circuits |
| 426 | +
|
| 427 | + Transpile Options: |
| 428 | + optimization_level (int): Optimization level to pass to |
| 429 | + :func:`qiskit.transpile`. |
| 430 | + num_processes (int): Number of processes to use during |
| 431 | + transpilation on Qiskit >= 1.0. |
| 432 | + full_transpile (bool): If ``True``, |
| 433 | + ``BaseExperiment._transpiled_circuits`` (called by |
| 434 | + :meth:`BaseExperiment.run` if not overridden by a subclass) |
| 435 | + will call :func:`qiskit.transpile` on the output of |
| 436 | + :meth:`BaseExperiment.circuits` before executing the circuits. |
| 437 | + If ``False``, ``BaseExperiment._transpiled_circuits`` will |
| 438 | + reindex the qubits in the output of |
| 439 | + :meth:`BaseExperiment.circuits` using the experiments' |
| 440 | + :meth:`BaseExperiment.physical_qubits`. Then it will check if |
| 441 | + the circuit operations are all defined in the |
| 442 | + :class:`qiskit.transpiler.Target` of the experiment's backend |
| 443 | + or in the indiivdual circuit calibrations. If not, it will use |
| 444 | + :class:`qiskit.transpiler.passes.BasisTranslator` to map the |
| 445 | + circuit instructions to the backend. Additionally, |
| 446 | + the :class:`qiskit.transpiler.passes.PulseGates` transpiler |
| 447 | + pass will be run if the :class:`qiskit.transpiler.Target` |
| 448 | + contains any custom pulse gate calibrations. |
| 449 | +
|
| 450 | + """ |
422 | 451 | # Experiment subclasses can override this method if they need
|
423 | 452 | # to set specific default transpiler options to transpile the
|
424 | 453 | # experiment circuits.
|
425 |
| - return Options(optimization_level=0) |
| 454 | + return copy.copy(DEFAULT_TRANSPILE_OPTIONS) |
426 | 455 |
|
427 | 456 | @property
|
428 | 457 | def transpile_options(self) -> Options:
|
|
0 commit comments