eclipse-qrisp / Qrisp

Qrisp - a framework for high-level programming of Quantum computers
https://www.qrisp.eu/
Eclipse Public License 2.0
83 stars 23 forks source link

Bug: Compilationaccelaration on QuantumBools #67

Closed Nik-SteinFraunh closed 1 week ago

Nik-SteinFraunh commented 1 month ago
  1. case: Occurs when Compilationaccelaration acts on QuantumBools/ConditionEnvironments, see code and attached screenshot. Work-Around in this case: have the cx in the less_than function act on res[0] instead of res
  2. case: Addtionally when derefferencing QuantumArrays with quantum floats another error occurs, see 2nd code block and second screenshot

1 . case:

        from qrisp import quantum_condition, cx, QuantumBool, QuantumArray, QuantumFloat, h, QuantumVariable
        qarray_size = 8
        nq = 4
        qtype = QuantumFloat(nq, -2)
        a = 1.5
        b = 0.25
        c = a + b
        d = a + c
        q_array = QuantumArray(qtype)
        q_array[:] = [a,b,c,d]

        @quantum_condition
        def less_than(qf_0, qf_1):
            temp_qf = qf_0 - qf_1
            res = QuantumBool()
            cx(temp_qf.sign(), res)
            return res

        ac = QuantumVariable(1)    
        entry = q_array[3]
        pick = q_array[1]
        with less_than(entry, pick):
            h(ac)

Bild

  1. case:
    ac = QuantumVariable(1)    
    inx = QuantumFloat(2, -2)
    entry = qf_array[4]
    pick = qf_array[inx]

    with less_than(entry, pick):
        #rz(np.pi/8, qb)
        h(ac)

bug_report

positr0nium commented 1 week ago

The first case is fixed with https://github.com/eclipse-qrisp/Qrisp/commit/4b480d036ab45c3c5e9e54050d73ead30320bf86 For the second case the syntax is wrong. What you want is achieved with:

with q_array[inx] as pick:
    with less_than(entry, pick):
        #rz(np.pi/8, qb)
        h(ac)