Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min_qubits kwarg to UnitarySynthesis pass #6349

Merged
merged 9 commits into from
Sep 30, 2021

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented May 4, 2021

Summary

This commit adds the UnitarySynthesis pass to the preset pass manager
anywhere unrolling of custom or wide gates was done. Previously, we only
ever called the UnitarySynthesis pass in the preset pass managers if the
basis translation method was set to 'synthesis' or we were using level3
and then it was part of the optimization pass (as part of 2q peephole
optimization). This was an issue in that we're implicitly calling the
_define() method of the class whenever we're unrolling gates >= 3q or
gates with a custom definition. The _define() method is basically
identical to the UnitarySynthesis pass except it doesn't expose the
options to set a basis gate or approximation degree, which would result
in the output gates from unitary gates in the unroll steps are always in
the U3 basis. This meant we would be converting unitary gates to u3 (and
cx) which would result in a conversion to the target basis later, even
if we could just go to the target basis directly.

This is also future proofing for #6124 where a plugin interface is added
to the UnitarySynthesis pass and can potentially be used for arbitrary
sized unitaries.
As #6124 merged prior to this PR this commit adds a
min_qubits option to the UnitarySynthesis pass to restrict the size of
unitary gates the pass will synthesize.

At the same time this change caught an issue with the SingleQubitUnitary
gate where the name was duplicated with the UnitaryGate which would
result in errors when UnitarySynthesis was called because the
UnitarySynthesis pass looks for gate named 'unitary' to run on. This is
fixed and the SingleQubitUnitary gate's name is changed to 'squ' to
differentiate it from the UnitaryGate.

Details and comments

@mtreinish mtreinish requested a review from a team as a code owner May 4, 2021 14:04
@mtreinish
Copy link
Member Author

I ran the QV benchmarks with this commit applied:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
-         179±2ms          131±3ms     0.74  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'translator')
-         580±8ms          398±4ms     0.69  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'translator')
-       3.61±0.1s       2.17±0.03s     0.60  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'translator')
-      1.78±0.01s          1.07±0s     0.60  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'translator')
-      6.56±0.01s       3.84±0.02s     0.58  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'translator')
-      38.0±0.5ms         15.0±2ms     0.40  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'translator')

Benchmarks that have stayed the same:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'synthesis')
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'synthesis')
        1.07±0.9s          8.90±9s    ~8.36  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'synthesis')
        78.1±40ms         108±80ms    ~1.39  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'synthesis')
         53.3±2ms       58.2±0.4ms     1.09  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'translator')

Benchmarks that have got worse:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
!         41.1±0s           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'synthesis')
!         9.07±7s           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'synthesis')
+     1.25±0.03ms       5.65±0.4ms     4.52  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'translator')
+     4.06±0.02ms      6.37±0.08ms     1.57  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'synthesis')
+      18.9±0.5ms       29.3±0.3ms     1.55  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'synthesis')

Based on this I'm thinking it might make sense to drop the extra UnitarySynthesis call from the synthesis translation method paths, I was on the fence about whether that was really necessary or not before.

@mtreinish
Copy link
Member Author

I ran a larger set of benchmarks including more qv to see the impact for larger circuits:

Benchmarks that have improved:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
-         180±4ms          137±5ms     0.76  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'translator')
-        556±10ms          398±4ms     0.72  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'translator')
-      1.76±0.05s       1.07±0.01s     0.61  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'translator')
-      3.67±0.05s       2.18±0.04s     0.59  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'translator')
-      37.9±0.4ms         15.0±2ms     0.40  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'translator')

Benchmarks that have stayed the same:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'synthesis')
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'synthesis')
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'synthesis')
           failed           failed      n/a  queko.QUEKOTranspilerBench.time_transpile_bss(3, None)
           failed           failed      n/a  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(3, None)
          20.6±3s          31.0±7s    ~1.51  queko.QUEKOTranspilerBench.time_transpile_bntf(3, 'sabre')
       67.1±0.3ms       72.2±0.3ms     1.08  queko.QUEKOTranspilerBench.time_transpile_bigd(2, None)
       51.0±0.4ms       54.0±0.3ms     1.06  queko.QUEKOTranspilerBench.time_transpile_bigd(0, None)
       94.9±0.5ms        100±0.5ms     1.05  queko.QUEKOTranspilerBench.time_transpile_bigd(1, None)
          177±1ms        186±0.3ms     1.05  queko.QUEKOTranspilerBench.time_transpile_bigd(2, 'sabre')
       85.1±0.6ms       89.0±0.5ms     1.05  queko.QUEKOTranspilerBench.time_transpile_bigd(1, 'sabre')
       59.2±0.5ms       61.5±0.2ms     1.04  queko.QUEKOTranspilerBench.time_transpile_bigd(0, 'sabre')
       9.53±0.02s       9.81±0.08s     1.03  queko.QUEKOTranspilerBench.time_transpile_bss(2, None)
          402±2ms          411±5ms     1.02  queko.QUEKOTranspilerBench.time_transpile_bigd(3, 'sabre')
          403±4ms          412±1ms     1.02  queko.QUEKOTranspilerBench.time_transpile_bntf(2, None)
        172±0.9ms        176±0.7ms     1.02  queko.QUEKOTranspilerBench.time_transpile_bigd(3, None)
       2.60±0.01s          2.65±0s     1.02  queko.QUEKOTranspilerBench.time_transpile_bss(1, None)
          828±4ms          842±1ms     1.02  queko.QUEKOTranspilerBench.time_transpile_bntf(0, None)
          751±3ms          763±6ms     1.02  queko.QUEKOTranspilerBench.time_transpile_bntf(3, None)
       2.35±0.03s          2.37±0s     1.01  queko.QUEKOTranspilerBench.time_transpile_bss(0, None)
          9.58±0s       9.62±0.06s     1.01  queko.QUEKOTranspilerBench.time_transpile_bss(1, 'sabre')
       10.7±0.02s          10.8±0s     1.00  queko.QUEKOTranspilerBench.time_transpile_bss(2, 'sabre')
       5.28±0.01s       5.30±0.01s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(2, 'sabre')
       6.59±0.01s          6.61±0s     1.00  queko.QUEKOTranspilerBench.time_transpile_bss(0, 'sabre')
       3.88±0.01s       3.89±0.02s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(1, 'sabre')
       2.13±0.01s       2.13±0.02s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(1, None)
              448              448     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(0, 'sabre')
              335              335     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(0, None)
              128              128     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(1, 'sabre')
              215              215     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(1, None)
              125              125     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, 'sabre')
               40               40     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, None)
              242              242     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, 'sabre')
              100              100     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, None)
             1001             1001     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(0, 'sabre')
             1024             1024     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(0, None)
              581              581     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(1, 'sabre')
              871              871     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(1, None)
              617              617     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, 'sabre')
               33               33     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, None)
              812              812     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(3, 'sabre')
               51               51     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(3, None)
              773              773     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(0, 'sabre')
             1400             1400     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(0, None)
              727              727     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(1, 'sabre')
             1259             1259     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(1, None)
              605              605     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(2, 'sabre')
             1243             1243     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(2, None)
              559              559     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(3, 'sabre')
       2.58±0.02s       2.57±0.01s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(0, 'sabre')
       20.5±0.02s       20.3±0.02s     0.99  queko.QUEKOTranspilerBench.time_transpile_bss(3, 'sabre')
             2577             2528     0.98  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(1)
       58.9±0.5ms       57.3±0.7ms     0.97  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'translator')
             2577             2501     0.97  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(2)
             2510             2419     0.96  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(0)
        96.8±50ms        89.6±60ms     0.93  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'synthesis')
             2686             2473     0.92  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(3)
        6.37±0.1s       3.81±0.04s    ~0.60  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'translator')

Benchmarks that have got worse:

       before           after         ratio
     [a0fae453]       [00a071d8]
     <unitary-synthesis-unroll~1>       <unitary-synthesis-unroll>
!       834±300ms           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'synthesis')
!         25.6±9s           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'synthesis')
+     1.25±0.03ms       5.46±0.4ms     4.37  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'translator')
+      2.44±0.04s       4.46±0.01s     1.82  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(0)
+      2.90±0.08s       5.15±0.01s     1.78  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(1)
+      4.15±0.3ms       6.73±0.3ms     1.62  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'synthesis')
+      18.3±0.2ms       29.3±0.5ms     1.60  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'synthesis')
+         24.4±0s       36.1±0.03s     1.48  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(3)
+      8.69±0.02s       12.1±0.01s     1.39  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(2)

It looks like this reduces the output depth for the 50x20 model circuit but also significantly increases the run time. Not sure what the best path forward here is anymore

This commit adds the UnitarySynthesis pass to the preset pass manager
anywhere unrolling of custom or wide gates was done. Previously, we only
ever called the UnitarySynthesis pass in the preset pass managers if the
basis translation method was set to 'synthesis' or we were using level3
and then it was part of the optimization pass (as part of 2q peephole
optimization). This was an issue in that we're implicitly calling the
_define() method of the class whenever we're unrolling gates >= 3q or
gates with a custom definition. The _define() method is basically
identical to the UnitarySynthesis pass except it doesn't expose the
options to set a basis gate or approximation degree, which would result
in the output gates from unitary gates in the unroll steps are always in
the U3 basis. This meant we would be converting unitary gates to u3 (and
cx) which would result in a conversion to the target basis later, even
if we could just go to the target basis directly.

This is also future proofing for Qiskit#6124 where a plugin interface is added
to the UnitarySynthesis pass and can potentially be used for arbitrary
sized unitaries.

At the same time this change caught an issue qith the SingleQubitUnitary
gate where the name was duplicated with the UnitaryGate which would
result in errors when UnitarySynthesis was called because the
UnitarySynthesis pass looks for gate named 'unitary' to run on. This is
fixed and the SingleQubitUnitary gate's name is changed to 'squ' to
differentiate it from the UnitaryGate.
@mtreinish mtreinish force-pushed the unitary-synthesis-unroll branch from 00a071d to a501fce Compare May 5, 2021 15:06
@kdk
Copy link
Member

kdk commented May 5, 2021

I like the direction in which this is heading (I think _define for everything other than custom gates is something we should start moving away from). For the benchmarks that timed out, it'd be good to understand why they're slower (and roughly by how much).

@ajavadia
Copy link
Member

This is still just decomposing unitaries, right? e.g. a Toffoli would not be expanded using UnitarySynthesis (which would be very inefficient).

What do you mean by this @kdk ?

I think _define for everything other than custom gates is something we should start moving away from

This commit adds a new option to the UnitarySynthesis pass constructor,
min_qubits, which is used to specify a minimimum size unitary to
synthesize. If the unitary is smaller than that it will be skipped. This
is then used by the UnitarySynthesis instance in the unroll3q phase so
we don't decompose 1 or 2q unitaries before routing.
@kdk
Copy link
Member

kdk commented May 24, 2021

This is still just decomposing unitaries, right? e.g. a Toffoli would not be expanded using UnitarySynthesis (which would be very inefficient).

Right, this keeps the same unitary synthesis approach, but tries to apply it in a more uniform and general way. Before this, a UnitaryGate in a circuit would (depending on the optimization_level) be decomposed first by UnrollCustomDefinitions through _define, which doesn't respect e.g. basis_gates or approximation_degree, and so might require further translation to end up in the basis_gates. This PR tries to use UnitarySynthesis everywhere we need to synthesize a unitary.

What do you mean by this @kdk ?

I think _define for everything other than custom gates is something we should start moving away from

For the places we use _define to set up a dynamic definition of a gate (the unroller, unitary synthesis, isometries, Clifford synthesis, ...), we're better off handling these as independent transpiler passes because it both makes the gate objects lighter (and so circuit copies/transformations will be faster) and it gives the transpiler more flexibility in how to re-write a given gate, depending on its context and the backend being targeted.

@kdk
Copy link
Member

kdk commented May 24, 2021

@mtreinish Do you have a set of updated benchmark numbers after 401aedf ?

@mtreinish
Copy link
Member Author

I just reran the benchmarks with the current state of the PR here are the results:

Benchmarks that have improved:

       before           after         ratio
     [9f28ad73]       [ead08031]
     <main>           <unitary-synthesis-unroll>
-        750±30ms         629±40ms     0.84  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'translator')
-      1.42±0.09s       1.18±0.07s     0.83  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'translator')

Benchmarks that have stayed the same:

       before           after         ratio
     [9f28ad73]       [ead08031]
     <main>           <unitary-synthesis-unroll>
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'synthesis')
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'synthesis')
           failed           failed      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'synthesis')
           failed           failed      n/a  queko.QUEKOTranspilerBench.time_transpile_bss(3, None)
           failed           failed      n/a  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(3, None)
        664±300ms        1.07±0.3s    ~1.61  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'synthesis')
         71.5±1ms       76.9±0.3ms     1.08  queko.QUEKOTranspilerBench.time_transpile_bigd(2, None)
       44.3±0.4ms       47.2±0.4ms     1.07  queko.QUEKOTranspilerBench.time_transpile_bigd(0, None)
          224±1ms        236±0.4ms     1.05  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm_backend_with_prop(0)
       96.2±0.6ms          101±1ms     1.05  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm(0)
         80.9±1ms       84.8±0.3ms     1.05  queko.QUEKOTranspilerBench.time_transpile_bigd(1, 'sabre')
       14.1±0.1ms       14.7±0.1ms     1.05  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'translator')
       52.0±0.3ms       54.3±0.1ms     1.04  queko.QUEKOTranspilerBench.time_transpile_bigd(0, 'sabre')
       87.9±0.4ms         91.4±1ms     1.04  queko.QUEKOTranspilerBench.time_transpile_bigd(1, None)
          240±1ms        248±0.8ms     1.03  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm(1)
        195±0.9ms        201±0.9ms     1.03  queko.QUEKOTranspilerBench.time_transpile_bigd(2, 'sabre')
          298±1ms        307±0.7ms     1.03  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm(3)
          455±2ms          467±2ms     1.02  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm_backend_with_prop(1)
          796±3ms          813±4ms     1.02  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm(2)
       13.7±0.06s        13.9±0.1s     1.02  queko.QUEKOTranspilerBench.time_transpile_bntf(3, 'sabre')
       2.78±0.02s       2.83±0.01s     1.02  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(1)
          422±5ms        428±0.9ms     1.01  queko.QUEKOTranspilerBench.time_transpile_bntf(2, None)
       3.04±0.01s       3.08±0.01s     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(3)
        405±0.6ms          411±2ms     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(1)
          401±1ms        406±0.7ms     1.01  queko.QUEKOTranspilerBench.time_transpile_bigd(3, 'sabre')
       20.0±0.08s       20.3±0.04s     1.01  queko.QUEKOTranspilerBench.time_transpile_bss(3, 'sabre')
       23.3±0.03s       23.6±0.02s     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(3)
       8.59±0.02s       8.67±0.04s     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(2)
        272±0.5ms        274±0.5ms     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(0)
       1.31±0.01s       1.32±0.02s     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(2)
       2.30±0.03s          2.31±0s     1.01  queko.QUEKOTranspilerBench.time_transpile_bss(0, None)
          704±5ms          708±1ms     1.01  queko.QUEKOTranspilerBench.time_transpile_bntf(0, None)
          1.02±0s          1.03±0s     1.01  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm_backend_with_prop(2)
       2.31±0.01s          2.32±0s     1.00  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(0)
          587±6ms          589±4ms     1.00  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_from_large_qasm_backend_with_prop(3)
              812              813     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(3, 'sabre')
              448              448     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(0, 'sabre')
              335              335     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(0, None)
              128              128     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(1, 'sabre')
              215              215     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(1, None)
              125              125     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, 'sabre')
               40               40     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, None)
              242              242     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, 'sabre')
              100              100     1.00  queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, None)
             1001             1001     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(0, 'sabre')
             1024             1024     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(0, None)
              581              581     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(1, 'sabre')
              871              871     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(1, None)
              617              617     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, 'sabre')
               33               33     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, None)
               51               51     1.00  queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(3, None)
              773              773     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(0, 'sabre')
             1400             1400     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(0, None)
              727              727     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(1, 'sabre')
             1259             1259     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(1, None)
              605              605     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(2, 'sabre')
             1243             1243     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(2, None)
              559              559     1.00  queko.QUEKOTranspilerBench.track_depth_bss_optimal_depth_100(3, 'sabre')
             2510             2510     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(0)
             2577             2577     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(1)
             2577             2577     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(2)
             2686             2686     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(3)
             2705             2705     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm(0)
             2005             2005     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm(1)
             2005             2005     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm(2)
                7                7     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm(3)
             4705             4705     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm_backend_with_prop(0)
             2005             2005     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm_backend_with_prop(1)
             2005             2005     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm_backend_with_prop(2)
                7                7     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_from_large_qasm_backend_with_prop(3)
              766              766     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(0)
              677              677     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(1)
              677              677     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(2)
              705              705     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(3)
       5.18±0.03s       5.18±0.06s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(2, 'sabre')
          172±1ms        172±0.8ms     1.00  queko.QUEKOTranspilerBench.time_transpile_bigd(3, None)
       3.89±0.01s       3.89±0.04s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(1, 'sabre')
          785±9ms          784±4ms     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(3, None)
       10.5±0.04s       10.5±0.08s     1.00  queko.QUEKOTranspilerBench.time_transpile_bss(2, 'sabre')
       2.49±0.02s       2.49±0.01s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(0, 'sabre')
          1.96±0s       1.96±0.02s     1.00  queko.QUEKOTranspilerBench.time_transpile_bntf(1, None)
       6.47±0.03s       6.44±0.04s     1.00  queko.QUEKOTranspilerBench.time_transpile_bss(0, 'sabre')
       2.56±0.03s       2.53±0.04s     0.99  queko.QUEKOTranspilerBench.time_transpile_bss(1, None)
       9.43±0.05s       9.29±0.06s     0.99  queko.QUEKOTranspilerBench.time_transpile_bss(1, 'sabre')
       10.3±0.03s       10.1±0.08s     0.98  queko.QUEKOTranspilerBench.time_transpile_bss(2, None)
         25.7±1ms         22.6±2ms    ~0.88  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'translator')
         73.2±2ms         63.9±4ms    ~0.87  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'translator')
        2.58±0.1s        2.14±0.2s    ~0.83  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'translator')
         235±20ms         186±10ms    ~0.79  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'translator')
        93.1±20ms        59.2±30ms    ~0.64  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'synthesis')

Benchmarks that have got worse:

       before           after         ratio
     [9f28ad73]       [ead08031]
     <main>           <unitary-synthesis-unroll>
+        1.17±0ms      3.64±0.06ms     3.10  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'translator')
+         7.47±0s          12.7±3s     1.69  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'synthesis')
+     3.99±0.02ms      6.38±0.05ms     1.60  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'synthesis')
+      18.2±0.2ms       28.6±0.1ms     1.57  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'synthesis')

In Qiskit#6124 which recently merged the UnitarySynthesis pass was added to
preset passmanager to enable synthesis plugins that operate on > 2q from
having an impact (otherwise they wouldn't be called). However that PR
didn't have the option to avoid synthesizing 2q unitaries too early.
This commit updates the base branch to the latest state of main which
includes Qiskit#6124. This means this PR just adds a min_qubits option to
UnitarySynthesis and leverages it for the unroll3q stage in the
preset pass managers.
@mtreinish mtreinish changed the title Rely on UnitarySynthesis pass for unrolling UnitaryGates Add min_qubits kwarg to UnitarySynthesis pass Sep 30, 2021
@mtreinish
Copy link
Member Author

So now that #6124 has merged I think this is more important. (mostly because I forgot about this until just now) Since the current state of main we'll be synthesizing unitaries too early without this PR.

@mtreinish mtreinish added this to the 0.19 milestone Sep 30, 2021
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Sep 30, 2021
@mtreinish
Copy link
Member Author

I ran numbers again comparing main to this PR:

Benchmarks that have improved:

       before           after         ratio
     [4eda7993]       [7f4c0889]
     <main>       <unitary-synthesis-unroll>
           failed       20.0±0.09s      n/a  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'synthesis')
-      4.13±0.02s       3.42±0.05s     0.83  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'translator')
-      2.35±0.01s       1.90±0.08s     0.81  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'translator')
-         1.16±0s         897±30ms     0.77  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'translator')
-         405±5ms          303±3ms     0.75  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'translator')
-         131±4ms         92.1±3ms     0.71  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'translator')
-     38.1±0.08ms       25.0±0.1ms     0.66  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'synthesis')

Benchmarks that have stayed the same:

       before           after         ratio
     [4eda7993]       [7f4c0889]
     <main>       <unitary-synthesis-unroll>
      1.36±0.01ms      1.48±0.01ms     1.09  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'translator')
        93.2±20ms        98.1±20ms     1.05  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'synthesis')
      2.52±0.02ms      2.62±0.01ms     1.04  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'synthesis')
      17.5±0.07ms      17.8±0.07ms     1.02  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'translator')
         354±50ms         240±30ms    ~0.68  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'synthesis')
       46.8±0.4ms         30.1±2ms    ~0.64  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'translator')
        6.09±0.1s        3.85±0.2s    ~0.63  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'synthesis')
        17.1±0.1s        10.0±0.3s    ~0.58  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'synthesis')
        1.93±0.2s       1.11±0.05s    ~0.58  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'synthesis')

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.

Although main in this comparison has #6124 which introduced the regression. I can run comparing this to prior to #6124 if people are interested (or with other benchmarks too).

Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. It would be good to compare this to main to see if the earlier regression ( after 401aedf in #6349 (comment) ) was resolved, but only because as I understand it, this PR should be functionally identical to what had been on main for those cases, just with the synthesis occurring under a different pass. That can wait though until after we get the benchmarking results back and see where we stand.

@kdk kdk added the automerge label Sep 30, 2021
@mtreinish
Copy link
Member Author

mtreinish commented Sep 30, 2021

Well the only places this will be different is because we added extra passes to the pipeline compared to the state prior to #6124 and even the min_qubits=3 only case that results in an extra dag iteration (from calling named_nodes) for each new UnitarySynthesis.run(). It shouldn't be huge but it can add up. Oh, and the other difference is that this will have the full set of synthesis options set while before it was always using the defaults.

I do have it on my todo list to add a retworkx side topological order search function similar to: Qiskit/rustworkx#456 to try and accelerate these cases a bit

@mtreinish
Copy link
Member Author

mtreinish commented Sep 30, 2021

I also ran larger QV comparisons just now and looked at depth too:

Benchmarks that have improved:

       before           after         ratio
     [4eda7993]       [7f4c0889]
     <main>       <unitary-synthesis-unroll>
-      6.00±0.01s       4.68±0.01s     0.78  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(1)
-             902              677     0.75  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(2)
-             916              677     0.74  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(1)
-         477±4ms        353±0.7ms     0.74  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(0)
-         1.55±0s          1.11±0s     0.72  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(2)
-      1.20±0.01s          807±3ms     0.67  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(1)
-             981              634     0.65  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(0)
-         5.42±0s       3.39±0.01s     0.63  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(3)
-            1168              709     0.61  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(3)
-      4.18±0.01s          2.46±0s     0.59  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(0)

Benchmarks that have stayed the same:

       before           after         ratio
     [4eda7993]       [7f4c0889]
     <main>       <unitary-synthesis-unroll>
             2473             2686     1.09  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(3)
             2419             2510     1.04  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(0)
             2501             2577     1.03  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(2)
             2528             2577     1.02  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(1)
       8.27±0.01s       6.97±0.01s    ~0.84  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(2)
       30.3±0.07s       20.7±0.06s    ~0.68  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(3)

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.

@mtreinish
Copy link
Member Author

So comparing it to main prior to #6124 there is still a small regression after this PR but it's nowhere near as severe:

Benchmarks that have improved:

       before           after         ratio
     [c202e460]       [7f4c0889]
     <main~1>       <unitary-synthesis-unroll>
-      1.24±0.01s       1.11±0.01s     0.89  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(2)
-             766              634     0.83  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(0)
-     4.16±0.02ms      2.63±0.03ms     0.63  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'synthesis')

Benchmarks that have stayed the same:

       before           after         ratio
     [c202e460]       [7f4c0889]
     <main~1>       <unitary-synthesis-unroll>
       14.4±0.1ms       17.8±0.2ms    ~1.23  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'translator')
         25.6±1ms         30.8±3ms    ~1.20  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'translator')
         74.9±9ms         89.8±7ms    ~1.20  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(3, 'synthesis')
       4.42±0.01s       4.72±0.02s     1.07  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(1)
          3.21±0s       3.38±0.01s     1.05  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(3)
          6.67±0s          6.98±0s     1.05  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(2)
       20.4±0.01s       20.8±0.04s     1.02  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(3)
      24.5±0.07ms      24.9±0.07ms     1.02  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(2, 'synthesis')
        1.15±0.1s       1.16±0.07s     1.01  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'synthesis')
             2510             2510     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(0)
             2577             2577     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(1)
             2577             2577     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(2)
             2686             2686     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_quantum_volume_transpile_50_x_20(3)
              677              677     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(1)
              677              677     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(2)
              709              709     1.00  transpiler_levels.TranspilerLevelBenchmarks.track_depth_transpile_qv_14_x_14(3)
       3.58±0.06s        3.56±0.1s     0.99  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'synthesis')
         238±60ms         230±10ms     0.97  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'synthesis')
        10.4±0.7s        9.79±0.1s     0.94  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'synthesis')
          21.4±2s       20.0±0.05s     0.93  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'synthesis')
          878±5ms          807±3ms     0.92  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(1)

Benchmarks that have got worse:

       before           after         ratio
     [c202e460]       [7f4c0889]
     <main~1>       <unitary-synthesis-unroll>
+       254±0.6ms        348±0.6ms     1.37  transpiler_levels.TranspilerLevelBenchmarks.time_transpile_qv_14_x_14(0)
+        224±10ms         288±10ms     1.28  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(8, 'translator')
+        73.6±1ms         91.2±3ms     1.24  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(5, 'translator')
+      2.54±0.01s       3.12±0.01s     1.23  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(27, 'translator')
+        746±50ms         907±40ms     1.22  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(14, 'translator')
+       1.50±0.1s       1.75±0.01s     1.17  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(20, 'translator')
+     1.29±0.01ms      1.47±0.01ms     1.14  quantum_volume.QuantumVolumeBenchmark.time_ibmq_backend_transpile(1, 'translator')
+      2.21±0.01s          2.46±0s     1.12  transpiler_levels.TranspilerLevelBenchmarks.time_quantum_volume_transpile_50_x_20(0)

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE DECREASED.

After this merges I'll see what else I can come up with to fix that remaining ~10-20% overhead.

@mergify mergify bot merged commit 5b5b376 into Qiskit:main Sep 30, 2021
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Oct 5, 2021
This commit tweaks the preset passmanager definitions to not include the
UnitarySynthesis pass as part of basis translation if the 'unitary' gate
is in the basis gates. Previously in Qiskit#6124 and Qiskit#6349 the preset
passmanagers were updated to leverage the user specified unitary
synthesis method instead of implicitly using the default as part of the
unroll 3q and unroll custom definition passes. This however had the
unintended side effect of always synthesizing unitary gates even if it
was in the basis (which is the case on Aer). This commit fixes this by
only running unitary synthesis as part of the basis translation step if
it's not in the basis.

A potential follow-on here is to make the unroll 3q transpiler pass
basis aware (since right now it will implicitly run unitary synthesis
internally) and add a similar logic around the use of the
UnitarySynthesis pass for unrolling 3q or larger gates. The unroll 3q
transpiler stage suffers from this same issue. However, this wasn't
done here because the way 3q unrolling is used is to reduce the gates to
be less than 3 qubits so the layout and routing phase can deal work with
the gates in the circuit would likely cause issues if a unitary gate
larger than 2 qubits was in the circuit being transpiled.
mtreinish added a commit that referenced this pull request Oct 6, 2021
)

* Ensure UnitaryGate's are preserved by transpile if in basis gates

This commit tweaks the preset passmanager definitions to not include the
UnitarySynthesis pass as part of basis translation if the 'unitary' gate
is in the basis gates. Previously in #6124 and #6349 the preset
passmanagers were updated to leverage the user specified unitary
synthesis method instead of implicitly using the default as part of the
unroll 3q and unroll custom definition passes. This however had the
unintended side effect of always synthesizing unitary gates even if it
was in the basis (which is the case on Aer). This commit fixes this by
only running unitary synthesis as part of the basis translation step if
it's not in the basis.

A potential follow-on here is to make the unroll 3q transpiler pass
basis aware (since right now it will implicitly run unitary synthesis
internally) and add a similar logic around the use of the
UnitarySynthesis pass for unrolling 3q or larger gates. The unroll 3q
transpiler stage suffers from this same issue. However, this wasn't
done here because the way 3q unrolling is used is to reduce the gates to
be less than 3 qubits so the layout and routing phase can deal work with
the gates in the circuit would likely cause issues if a unitary gate
larger than 2 qubits was in the circuit being transpiled.

* Skip level 3 in tests

The level 3 preset passmanager by default runs 2q block collection which
is then synthesized into a unitary. As long as we're running that in the
pass manager it's not really possible right now to preserve input
unitaries through the transpilation. A potential follow on PR could
potential skip the synthesis pass if 'unitary' is in the basis so the
optimization pass would just collect 2q blocks into a unitary and pass
that to the backend directly. However, that's not in scope for this PR
(and it's not clear if we want that or not).

* Revert to main preset passmanager logic

As was pointed out by @jakelishman in code review. Prior to #6124 the
unitary synthesis pass was checking the basis for the presence of
unitary (and swap gates if pulse_optimize=True) in the basis set and
skipping the gates in the pass directly instead of in the pass manager.
This logic was lost when we added the plugin interface in #6124
(probably as part of a rebase as it was a long lived branch). Since we
used to have the logic in the pass itself this commit changes the
approach to not adjust the preset passmanager usage and just make the
pass detect if unitary is in the basis and not synthesize. This
simplifies the logic and makes it less error prone.

At the same time the test coverage is expanded to ensure we preserve
this behavior moving forward (as aer's testing requires it).

* Add level 3 back to tests

* Improve efficieny if gates to synthesize are in basis
@mtreinish mtreinish deleted the unitary-synthesis-unroll branch October 8, 2021 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants