def transpile(self, circuits): """ A wrapper to transpile circuits to allow algorithm access the transpiled circuits. Args: circuits (Union['QuantumCircuit', List['QuantumCircuit']]): circuits to transpile Returns: List['QuantumCircuit']: The transpiled circuits, it is always a list even though the length is one. """ # pylint: disable=cyclic-import from qiskit import compiler if self._pass_manager is not None: transpiled_circuits = self._pass_manager.run(circuits) else: transpiled_circuits = compiler.transpile(circuits, self._backend, **self._backend_config, **self._compile_config) if not isinstance(transpiled_circuits, list): transpiled_circuits = [transpiled_circuits] if logger.isEnabledFor(logging.DEBUG) and self._circuit_summary: logger.debug("==== Before transpiler ====") logger.debug(circuit_utils.summarize_circuits(circuits)) if transpiled_circuits is not None: logger.debug("==== After transpiler ====") logger.debug( circuit_utils.summarize_circuits(transpiled_circuits)) return transpiled_circuits
def transpile(self, circuits, pass_manager=None): """A wrapper to transpile circuits to allow algorithm access the transpiled circuits. Args: circuits (Union['QuantumCircuit', List['QuantumCircuit']]): circuits to transpile pass_manager (Optional['PassManager']): A pass manager to transpile the circuits. If none is given, but either ``pass_manager`` or ``bound_pass_manager`` has been set in the initializer, these are run. If none has been provided there either, the backend and compile configs from the initializer are used. Returns: List['QuantumCircuit']: The transpiled circuits, it is always a list even though the length is one. """ # pylint: disable=cyclic-import from qiskit import compiler from qiskit.transpiler import PassManager # if no pass manager here is given, check if they have been set in the init if pass_manager is None: # if they haven't been set in the init, use the transpile args from the init if self._pass_manager is None and self._bound_pass_manager is None: transpiled_circuits = compiler.transpile( circuits, self._backend, **self._backend_config, **self._compile_config) # it they have been set, run them else: pass_manager = PassManager() if self._pass_manager is not None: pass_manager += self._pass_manager # check if None if self._bound_pass_manager is not None: pass_manager += self._bound_pass_manager transpiled_circuits = pass_manager.run(circuits) # custom pass manager set by user else: transpiled_circuits = pass_manager.run(circuits) if not isinstance(transpiled_circuits, list): transpiled_circuits = [transpiled_circuits] if logger.isEnabledFor(logging.DEBUG) and self._circuit_summary: logger.debug("==== Before transpiler ====") logger.debug(circuit_utils.summarize_circuits(circuits)) if transpiled_circuits is not None: logger.debug("==== After transpiler ====") logger.debug( circuit_utils.summarize_circuits(transpiled_circuits)) return transpiled_circuits