0
$\begingroup$

I have got a 2-qubit circuit with the following instructions:

qc = QuantumCircuit(2,2)
qc.ry(2.1285844174659494, 0)
qc.u3(2.263106783376567, 0.3206834870221442, 0, 1)
qc.cx(1,0)
qc.u3(0.18291493410636106, -0.3915870470928269, 0.0, 0)
qc.cx(1,0)
qc.rz(0.17181884984660947, 0)

I guess I can reduce cx gates because cx commutes with u3. I check it via qiskit and numpy:

qc_ = QuantumCircuit(2)
qc_.u3(0.18291493410636106, -0.3915870470928269, 0.0, 1)
op1 = Operator(qc_.to_instruction()).data

qc_ = QuantumCircuit(2)
qc_.cx(1, 0)
op2 = Operator(qc_.to_instruction()).data
print((np.multiply(op1, op2) == np.multiply(op2, op1)).all())

The result is True.

However, the state fidelity of the original circuit and circuit without cx gates is 0.884. Do I understand correctly that I can remove the cx gates as far as cx and u3 can be permuted?

$\endgroup$
6
  • 2
    $\begingroup$ Is np.multiply() not elementwise multiplication? If two operators commute we have $AB = BA$ where multiplication is matrix multiplication (not elementwise). This will probably explain the discrepancy you observe when you try to use commutation to simplify the circuit. For matrix multiplication in numpy you want np.matmul() $\endgroup$
    – Rammus
    Jun 29, 2022 at 15:33
  • 1
    $\begingroup$ For the difference between NumPy.multiply and NumPy.matmul see here: mkang32.github.io/python/2020/08/30/numpy-matmul.html $\endgroup$ Jun 29, 2022 at 16:39
  • 1
    $\begingroup$ you also can use @ directly instead $\endgroup$
    – poig
    Jun 29, 2022 at 16:40
  • $\begingroup$ I recommend you to learn the related necessary things with pennylane codebook. you can follow walkthrough from owen lockwood youtube channel. $\endgroup$
    – poig
    Jun 29, 2022 at 16:44
  • 1
    $\begingroup$ also can use np.dot, detailed explanation: peps.python.org/pep-0465 $\endgroup$
    – poig
    Jun 29, 2022 at 17:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.