Skip to content

Commit

Permalink
Remove pformat from stochastic swap log messages (#3812)
Browse files Browse the repository at this point in the history
When profiling a level 0 transpile of a 20x50 random circuit the timing
data shows that after switching to retworkx the largest chunk of time in
in stochastic swap's _layer_permutation function is spent calling pformat
for log messages. This is just for debugging and is unecessary, and in a
world where we're no longer bottlenecked on dag operations a signifcant
cost to the run time.
  • Loading branch information
mtreinish authored Feb 11, 2020
1 parent 03083dc commit ed8f8f8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions qiskit/transpiler/passes/routing/stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Map a DAGCircuit onto a `coupling_map` adding swap gates."""

from logging import getLogger
from pprint import pformat
from math import inf
from collections import OrderedDict
import numpy as np
Expand Down Expand Up @@ -158,8 +157,8 @@ def _layer_update(self, i, best_layout, best_depth,
that the _mapper method is building.
"""
layout = best_layout
logger.debug("layer_update: layout = %s", pformat(layout))
logger.debug("layer_update: self.trivial_layout = %s", pformat(self.trivial_layout))
logger.debug("layer_update: layout = %s", layout)
logger.debug("layer_update: self.trivial_layout = %s", self.trivial_layout)
dagcircuit_output = DAGCircuit()
for qubit in layout.get_virtual_bits().keys():
if qubit.register not in dagcircuit_output.qregs.values():
Expand Down Expand Up @@ -292,10 +291,10 @@ def _mapper(self, circuit_graph, coupling_graph, trials=20):

# This is the final edgemap. We might use it to correctly replace
# any measurements that needed to be removed earlier.
logger.debug("mapper: self.trivial_layout = %s", pformat(self.trivial_layout))
logger.debug("mapper: layout = %s", pformat(layout))
logger.debug("mapper: self.trivial_layout = %s", self.trivial_layout)
logger.debug("mapper: layout = %s", layout)
last_edgemap = layout.combine_into_edge_map(self.trivial_layout)
logger.debug("mapper: last_edgemap = %s", pformat(last_edgemap))
logger.debug("mapper: last_edgemap = %s", last_edgemap)

return dagcircuit_output

Expand Down Expand Up @@ -326,11 +325,11 @@ def _layer_permutation(layer_partition, layout, qubit_subset,
TranspilerError: if anything went wrong.
"""
logger.debug("layer_permutation: layer_partition = %s",
pformat(layer_partition))
layer_partition)
logger.debug("layer_permutation: layout = %s",
pformat(layout.get_virtual_bits()))
layout.get_virtual_bits())
logger.debug("layer_permutation: qubit_subset = %s",
pformat(qubit_subset))
qubit_subset)
logger.debug("layer_permutation: trials = %s", trials)

# The input dag is on a flat canonical register
Expand All @@ -344,7 +343,7 @@ def _layer_permutation(layer_partition, layout, qubit_subset,
raise TranspilerError("Layer contains > 2-qubit gates")
if len(gate_args) == 2:
gates.append(tuple(gate_args))
logger.debug("layer_permutation: gates = %s", pformat(gates))
logger.debug("layer_permutation: gates = %s", gates)

# Can we already apply the gates? If so, there is no work to do.
dist = sum([coupling.distance(layout[g[0]], layout[g[1]])
Expand Down

0 comments on commit ed8f8f8

Please sign in to comment.