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

Use Isometry to implement Initialize instruction #6760

Closed
EgrettaThula opened this issue Jul 17, 2021 · 2 comments
Closed

Use Isometry to implement Initialize instruction #6760

EgrettaThula opened this issue Jul 17, 2021 · 2 comments
Labels
type: enhancement It's working, but needs polishing

Comments

@EgrettaThula
Copy link
Contributor

EgrettaThula commented Jul 17, 2021

What is the expected enhancement?

As per documentation, Isometry instruction can be used for state preparation.
On the other hand, Initialize instruction does its work by first resetting the qubits to |0⟩ followed by an state preparing unitary.
That means circ.initialize is equivalent to circ.reset + circ.iso.

However, I noticed that using Isometry almost always results in a circuit with much less number of CNOTs.

n = 4
psi = random_statevector(2 ** n)

# Using initialize
qr1 = QuantumRegister(n)
qc1 = QuantumCircuit(qr1)
qc1.initialize(psi, qr1)
tr_qc1 = transpile(qc1, basis_gates = ['u', 'cx'], optimization_level = 3)
print('Initialize:', tr_qc1.count_ops())

# Using reset + iso
qr2 = QuantumRegister(n)
qc2 = QuantumCircuit(qr2)
qc2.reset(qr2)
qc2.iso(psi, qr2, [])
tr_qc2 = transpile(qc2, basis_gates = ['u', 'cx'], optimization_level = 3)
print('Isometry:', tr_qc2.count_ops())

The result is something like that:

Initialize: OrderedDict([('u', 26), ('cx', 22)])
Isometry: OrderedDict([('u', 15), ('cx', 11)])

So, I suggest to use Isometry to implement Initialize instruction. This should lead to a better end result with less code to maintain.

@EgrettaThula EgrettaThula added the type: enhancement It's working, but needs polishing label Jul 17, 2021
@Cryoris
Copy link
Contributor

Cryoris commented Jul 19, 2021

Isometry and Initialize use two different algorithms to construct the circuits. Rather than replace one with the other I think it would be better to keep synthesis part of Initialize (i.e. without the initial resets) in some class in Qiskit but have QuantumCircuit.initialize use the more efficient isometry instead.

@ShellyGarion
Copy link
Member

close in favor of #12081.
the separation of initialize to reset + state preparation was done in #7666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Projects
None yet
Development

No branches or pull requests

3 participants