question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve TwoLocal and RealAmplitudes synthesis when entanglement='full'

See original GitHub issue

What should we add?

When choosing a TwoLocal or RealAmplitude or EfficientSU2 gate with entanglement=full on n-qubits (for VQE ansatz), then we get a circuit with a CX sub-circuit that contains n*(n-1)/2 CX gates. However, we can re-write this circuit with only n-1 CX gates with a linear connectivity (see a code example below).

from qiskit.circuit.library import *
from qiskit.quantum_info import Operator

n = 5
# print (RealAmplitudes(n, reps=1, insert_barriers=True).decompose())
# now note that the CX-subcircuit is in fact the same as this qc below

qc = QuantumCircuit(n)
for i in range(n):
    for j in range(i+1, n):
        qc.cx(i,j)
# print ("qc", qc)
mat = LinearFunction(qc).linear
op = Operator(qc)

qc1 = QuantumCircuit(n)
for i in range(n-1):
    qc1.cx(n-i-2, n-i-1)
# print ("qc1", qc1)
mat1 = LinearFunction(qc).linear
op1 = Operator(qc1)

print((mat == mat1).all())
print (op == op1)

outputs:

True
True

It will be good to update either NLocal or TwoLocal to consider this specific enhancement, as it seems that this is used in many applications.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
ShellyGarioncommented, Jul 21, 2022

We have agreed upon the following API:

  • the new method will be called reverse_linear

  • the previous method will be called full (as it originally was)

  • the documentation will say that for a TwoLocal circuit, if entanglement_blocks='cx' then full and reverse_linear actually provide the same circuit

  • for RealAmplitudes and EfficientSU2 circuits, where always entanglement_blocks='cx', the default value for entanglement will be changed from full to reverse_linear

1reaction
Cryoriscommented, Jul 18, 2022

Yeah it seems these names were chosen by how they visually look like on the circuit, not by their effect. But at the moment I think these names are mostly just an identifier, without any rigour behind them. If you other suggestions I think we can change them 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

qiskit.circuit.library.RealAmplitudes
The entanglement can be set using the entanglement keyword as string or a list of index-pairs. See the documentation of TwoLocal and NLocal...
Read more >
qiskit-terra - bytemeta
Improve TwoLocal and RealAmplitudes synthesis when entanglement='full ' · QPY serialization does not preserve Delay time unit.
Read more >
Karma: Null Error from Percy Snapshots - GoogleForCreators/Web ...
Improve TwoLocal and RealAmplitudes synthesis when entanglement='full ', 12, 2022-07-05, 2022-10-01. Tar, drench, and heavy compressors, 8, 2021-12-26 ...
Read more >
Updating a node with an anchor removes the anchor - Mikefarah/Yq
Improve TwoLocal and RealAmplitudes synthesis when entanglement='full ', 12, 2022-07-05, 2022-11-04. Updating causes game crash after restart, 1, 2022-05-18 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found