1515Mapper for a quantum circuit to an arbitrary connected graph.
1616
1717Input: Quantum circuit with 1 and 2 qubit gates on n qubits. Gates are assumed
18- to be applied in parallel if they act on disjoint qubit(s) and any pair
19- of qubits can perform a 2 qubit gate (all-to-all connectivity)
18+ to be applied in parallel if they act on disjoint qubit(s) and any pair of
19+ qubits can perform a 2 qubit gate (all-to-all connectivity)
20+
2021Output: Quantum circuit in which qubits are placed in 2-D square grid in which
21- only nearest neighbour qubits can perform a 2 qubit gate. The mapper
22- uses Swap gates in order to move qubits next to each other.
22+ only nearest neighbour qubits can perform a 2 qubit gate. The mapper uses Swap
23+ gates in order to move qubits next to each other.
2324"""
2425from copy import deepcopy
2526
3940if sys .version_info [0 ] >= 3 and sys .version_info [1 ] > 6 : # pragma: no cover
4041
4142 def uniquify_list (seq ):
42- #pylint: disable=missing-function-docstring
43+ # pylint: disable=missing-function-docstring
4344 return list (dict .fromkeys (seq ))
4445else : # pragma: no cover
4546
4647 def uniquify_list (seq ):
47- #pylint: disable=missing-function-docstring
48+ # pylint: disable=missing-function-docstring
4849 seen = set ()
4950 seen_add = seen .add
5051 return [x for x in seq if x not in seen and not seen_add (x )]
@@ -53,6 +54,18 @@ def uniquify_list(seq):
5354# ==============================================================================
5455
5556
57+ class defaults (object ):
58+ """
59+ Class containing default values for some options
60+ """
61+ #: Defaults to :py:func:`.look_ahead_parallelism_cost_fun`
62+ cost_fun = look_ahead_parallelism_cost_fun
63+ max_swap_steps = 30
64+
65+
66+ # ==============================================================================
67+
68+
5669class GraphMapperError (Exception ):
5770 """Base class for all exceptions related to the GraphMapper."""
5871
@@ -78,7 +91,7 @@ def _add_qubits_to_mapping_fcfs(current_mapping, graph, new_logical_qubit_ids,
7891
7992 Returns: A new mapping
8093 """
81- #pylint: disable=unused-argument
94+ # pylint: disable=unused-argument
8295
8396 mapping = deepcopy (current_mapping )
8497 currently_used_nodes = sorted ([v for _ , v in mapping .items ()])
@@ -337,26 +350,20 @@ def __init__(self,
337350 * - Key
338351 - Type
339352 - Description
340- * - cost_fun
341- - ``function``
342- - | Cost function to be called when generating a new
343- | list of swap operations.
344- | Defaults to :py:func:`.look_ahead_parallelism_cost_fun`
345353 * - decay_opts
346354 - ``dict``
347355 - | Options to pass onto the :py:class:`.DecayManager`
348356 constructor
349- | Defaults to ``{'delta': 0.001, 'max_lifetime': 5}``.
350- * - opts
357+ | (see :py:class:`._gate_manager.defaults`)
358+ * - swap_opts
351359 - ``dict``
352- - | Extra options to pass onto the cost function
353- | (see :py:meth:`.MultiQubitGateManager.generate_swaps`)
354- | Defaults to ``{'W': 0.5}``.
355- * - max_swap_steps
356- - ``int``
357- - | Maximum number of swap steps per mapping
358- | (see :py:meth:`.MultiQubitGateManager.generate_swaps`)
359- | Defaults to 30
360+ - | Extra options used when generating a list of swap
361+ | operations.
362+ | Acceptable keys: W, cost_fun, near_term_layer_depth,
363+ | max_swap_steps
364+ | (see :py:meth:`.GateManager.generate_swaps`,
365+ | :py:class:`._graphmapper.defaults` and
366+ | :py:class:`._gate_manager.defaults`)
360367 """
361368 BasicMapperEngine .__init__ (self )
362369
@@ -542,12 +549,14 @@ def _run(self):
542549 if not self .qubit_manager .size ():
543550 return
544551
552+ # NB: default values are taken care of at place of access
553+ swap_opts = self ._opts .get ('swap_opts' , {})
554+
545555 swaps , all_swapped_qubits = self .qubit_manager .generate_swaps (
546556 self ._current_mapping ,
547- cost_fun = self ._opts .get ('cost_fun' ,
548- look_ahead_parallelism_cost_fun ),
549- opts = self ._opts .get ('opts' , {'W' : 0.5 }),
550- max_steps = self ._opts .get ('max_swap_steps' , 30 ))
557+ cost_fun = swap_opts .get ('cost_fun' , defaults .cost_fun ),
558+ opts = swap_opts ,
559+ max_steps = swap_opts .get ('max_swap_steps' , defaults .max_swap_steps ))
551560
552561 if swaps :
553562 # Get a list of the qubits we need to allocate just to perform the
0 commit comments