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

support cu1 fusion #334

Merged
merged 2 commits into from
Sep 6, 2019
Merged

support cu1 fusion #334

merged 2 commits into from
Sep 6, 2019

Conversation

hhorii
Copy link
Collaborator

@hhorii hhorii commented Aug 31, 2019

Summary

Support fusion of cu1

Details and comments

cu1 is a basic operator since #258, but has not been supported in fusion.

Copy link
Member

@atilag atilag left a comment

Choose a reason for hiding this comment

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

How is the improvement using this optimization?
Do we have some benchmarks?

@@ -15,6 +15,8 @@
#ifndef _aer_transpile_fusion_hpp_
#define _aer_transpile_fusion_hpp_

//#define DEBUG
Copy link
Member

Choose a reason for hiding this comment

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

You might have unintentionally left this commented line I guess.. :)

&& ops[i ].qubits[1] == ops[i + 1].qubits[0]
&& ops[i + 1].qubits[0] == ops[i + 2].qubits[1]
&& ops[i ].qubits[0] == ops[i + 2].qubits[0] )
if ((i + 3) <= until
Copy link
Member

Choose a reason for hiding this comment

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

it would be great if we can add a comment in this method to explain what is trying to do, something like:

// This method will seek for this pattern of gates in the circuit:
// ---[u1]---|---[u1]---|---
// --------[cx]-------[cx]--
// And optimize it by blablabla...

@atilag
Copy link
Member

atilag commented Sep 6, 2019

Thanks @hhorii !

@atilag atilag merged commit abd418e into Qiskit:master Sep 6, 2019
@hhorii
Copy link
Collaborator Author

hhorii commented Sep 7, 2019

@atilag With this PR, I confirmed 37% reduction of elapsed time of 25-qubit qft on MacBook Pro (2.6 GHz Intel Core i7, 16GB DDR4) .

import time
import math
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.compiler import assemble, transpile
from qiskit.providers.aer import QasmSimulator

def qft(qreg, circuit):
    n = len(qreg)
    for i in range(n):
        circuit.h(qreg[i])
    for i in range(n):
        for j in range(i):
            circuit.cu1(math.pi/float(2**(i-j)), qreg[i], qreg[j])
        circuit.h(qreg[i])
    return circuit

qubit = 25
backend = QasmSimulator()

print ('app,qubit,time')

backend_options = {}
backend_options['fusion_enable'] = True

q = QuantumRegister(qubit,"q")
c = ClassicalRegister(qubit, "c")
circ = qft(q, QuantumCircuit(q, c, name="qft"))
circ.barrier()
for i in range(qubit):
    circ.measure(q[i], c[i])

qobj = assemble(circ)

start_simulation = time.time()
backend.run(qobj, backend_options=backend_options).result()
end_simulation = time.time()

print ('qft,{qubit},{simulation}'.format(
    qubit=qubit, 
    simulation=(end_simulation - start_simulation)))
before:
app,qubit,time
qft,25,7.1155619621276855

after:
app,qubit,time
qft,25,4.471642017364502

dcmckayibm pushed a commit to dcmckayibm/qiskit-aer that referenced this pull request Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants