Giter Site home page Giter Site logo

Comments (2)

SimoneGasperini avatar SimoneGasperini commented on June 12, 2024 1

Thank you @adrianor for reporting this.
The problem here arises from a minor difference in the signature of the controlled unitary gate in Qiskit and in qiskit-symb. In Qiskit, the CUGate constructor (and the corresponding QuantumCircuit.cu method you are using in your code) takes 3 angles theta, phi, lam + the global phase gamma while, in qiskit-symb, the last parameter gamma is omitted.
From my point of view, this is actually a small but relevant inconsistency in Qiskit, since CUGate is the only gate that takes one extra "angle parameter" compared to its corresponding UGate (not controlled) and indeed several open issues on the main qiskit-terra repository are related to this problem (e.g. Qiskit/qiskit#9763, Qiskit/qiskit#7326).

However, this is for sure not handled correctly in qiskit-symb and the error message is very misleading. So, waiting for the problem to be properly solved in Qiskit itself, I can temporarily fix qiskit-symb so that it shows an appropriate error message by marking the CUGate as "not implemented".

from qiskit-symb.

SimoneGasperini avatar SimoneGasperini commented on June 12, 2024

Meanwhile, you can use the Qiskit transpiler to work around the problem and run your code with no errors:

import numpy as np
from qiskit import transpile
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit, Parameter
from qiskit_symb.utils import get_symbolic_gates_names

st0 = Parameter("st0")
st1 = Parameter("st1")

def u1red_cr_overrot(alpha, theta):
    qreg_q = QuantumRegister(2, "q")
    creg_c = ClassicalRegister(2, "c")
    circuit = QuantumCircuit(qreg_q, creg_c)
    circuit.u(1.570796326794897, -2.9755113931440857, 4.71238898038469 + st1, qreg_q[1])
    circuit.u(1.8942714348583476, -4.71238898038469, 0.0 + st0, qreg_q[0])
    circuit.cu(np.pi / 2, np.pi / 2, -np.pi / 2, 0, qreg_q[1], qreg_q[0])
    symbolic_gates = get_symbolic_gates_names()
    symbolic_gates.remove("cu")
    circuit = transpile(circuit, basis_gates=symbolic_gates)
    return qreg_q, creg_c, circuit

In this case, the CUGate transforms into a CU3Gate but the final circuit is always exactly equivalent to the original. Note that this also works correctly when the global phase parameter gamma is not 0.

from qiskit-symb.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.