8

Does anyone know how to make a quantum circuit to compute exponentials where the exponent can be a fraction? To be more precise, I'm looking for a fixed point quantum arithmetic circuit that does the following:

$$|\vec{x}\rangle|\vec{0}\rangle \rightarrow |\vec{x}\rangle|e^x\rangle$$

where $|\vec{x}\rangle = |x_2x_1x_0x_{-1}x_{-2}\rangle$ is a $5$ qubit register, $|\vec{0}\rangle$ is an $n$ qubit register and where $x$ represents the binary number $$x = x_2\times 2^2 + x_1\times 2^1 + x_0\times 2^0+x_{-1}\times 2^{-1}+ x_{-2}\times 2^{-2}$$

and where $|e^x\rangle$ holds the fixed point representation of $e^x$ to within an error of $\epsilon$ (therefore the value of $n$ will be chosen based on the value of the desired $\epsilon$)

glS
  • 27,670
  • 7
  • 39
  • 126
sheesymcdeezy
  • 2,041
  • 8
  • 27

4 Answers4

4

If $x$ is only 5 bits long, your best bet is almost definitely to just encode all the possible answers into a QROM circuit and do a lookup.

Here's a QROM circuit diagram from https://arxiv.org/abs/1805.036621:

enter image description here

And here's Q# source code for constructing a lookup circuit, from ancillary files of https://arxiv.org/abs/1905.076821.

/// # Summary
/// Performs 'a ^^^= T[b]' where 'a' and 'b' are little-endian quantum registers
/// and 'T' is a classical table.
///
/// Bits in 'T[b]' beyond the range of 'a' are ignored.
/// It is assumed that the address will never store a value beyond the end of the table.
/// Invalid addresses cause undefined behavior.
///
/// # Input
/// ## lvalue
/// The target of the xor. The 'a' in 'a ^^^= T[b]'.
/// ## table
/// The classical table containing integers to choose between and xor into the target.
/// The 'T' in 'a ^^^= T[b]'.
/// ## address
/// Determines which integer from the table will be xored into the target.
/// The 'b' in 'a ^^^= T[b]'.
operation XorEqualLookup (lvalue: LittleEndian, table: BigInt[], address: LittleEndian) : Unit {
    body (...) {
        Controlled XorEqualLookup(new Qubit[0], (lvalue, table, address));
    }
    adjoint self;
    controlled (cs, ...) {
        if (Length(table) == 0) {
            fail "Can't lookup values in an empty table.";
        }
    // Drop high bits that would place us beyond the range of the table.
    let maxAddressLen = CeilLg2(Length(table));
    if (maxAddressLen < Length(address!)) {
        let kept = LittleEndian(address![0..maxAddressLen - 1]);
        return Controlled XorEqualLookup(cs, (lvalue, table, kept));
    }

    // Drop inaccessible parts of table.
    let maxTableLen = 1 <<< Length(address!);
    if (maxTableLen < Length(table)) {
        let kept = table[0..maxTableLen-1];
        return Controlled XorEqualLookup(cs, (lvalue, kept, address));
    }

    // Base case: singleton table.
    if (Length(table) == 1) {
        XorEqualConst(address, ToBigInt(-1));
        Controlled XorEqualConst(cs + address!, (lvalue, table[0]));
        XorEqualConst(address, ToBigInt(-1));
        return ();
    }

    // Recursive case: divide and conquer.
    let highBit = address![Length(address!) - 1];
    let restAddress = LittleEndian(address![0..Length(address!) - 2]);
    let h = 1 <<< (Length(address!) - 1);
    let lowTable = table[0..h-1];
    let highTable = table[h..Length(table)-1];
    using (q = Qubit()) {
        // Store 'all(controls) and not highBit' in q.
        X(highBit);
        Controlled InitToggle(cs + [highBit], q);
        X(highBit);

        // Do lookup for half of table where highBit is 0.
        Controlled XorEqualLookup([q], (lvalue, lowTable, restAddress));

        // Flip q to storing 'all(controls) and highBit'.
        Controlled X(cs, q);

        // Do lookup for half of table where highBit is 1.
        Controlled XorEqualLookup([q], (lvalue, highTable, restAddress));

        // Eager uncompute 'q = all(controls) and highBit'.
        Controlled UncomputeToggle(cs + [highBit], q);
    }
}
controlled adjoint self;

}


1 Note: I'm an author

Mithrandir24601
  • 3,816
  • 3
  • 24
  • 45
Craig Gidney
  • 47,099
  • 1
  • 44
  • 119
1

This might not be the most ideal implementation but an interesting way you could approximate this is using $R_y$s and $QFT^{-1}$.

If we Taylor expand $e^x = 1 + x + \frac{x^2}{2!} ...$ we can use the polynomial amplitude encoding in https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-019-0130-6/MediaObjects/41534_2019_130_MOESM1_ESM.pdf, Section D.

Using the example from the paper for a polynomial $p(x) = ax^2 + bx + c$, where we substitute our coefficients from the Taylor expansion, we can apply the controlled $R_y$s to an ancilla:

$ U_{e^x}|0\rangle = R_y(1.5)^{q_2}R_y(2)^{q_1,q_2}R_y(4)^{q_1}R_y(1)|0\rangle \rightarrow \cos(e^x/2)|0\rangle + \sin(e^x/2)|1\rangle$.

We can use take QFT of the ancilla to a register $|R\rangle$

$QFT^{-1}U_{e^x}|0\rangle|R\rangle \rightarrow U_{e^x}|0\rangle|\sin(e^x/2)\rangle$.

Finally we can use the approximation $\sin(x) \approx x$ assuming $x$ is sufficiently small. We can control this by scaling the Taylor approximation polynomial.

$QFT^{-1}U_{e^x}|0\rangle|R\rangle \rightarrow U_{e^x}|0\rangle|\sin(e^x/2)\rangle \approx U_{e^x}|0\rangle|e^x/2\rangle $

The main caveat is we need to ensure the correct scaling, with a constant $K$, ideally we would like our scaling s.t. $\sup Ke^x < \frac{\pi}{4}$ in our domain of $x$. As such we would obtain

$|Ke^x/2\rangle$,

and then we would need to have a circuit to descale. If we take $K$ in the form of $2^{-n}$, then in fact we don't need to implement a descaling circuit and we can just rescale the values of the coefficients of our binary representation by $2^{n+1}$ to recover our approximation to $e^x$.

Note: Here was are assuming $x$ is a binary integer.

Sam Palmer
  • 1,009
  • 5
  • 12
1

Leaving this here. Recently published, might be useful for this question.

Efficient Evaluation of Exponential and Gaussian Functions on a Quantum Computer https://arxiv.org/abs/2110.05653

jecado
  • 1,251
  • 6
  • 18
Sam Palmer
  • 1,009
  • 5
  • 12
0

Based on previous work (including a large part the work on the lookup table by @Craig Gidney described in his answer here) we put out some recent work where we create a circuit that implements $e^x$ which is (as far as we know to date) is the most efficient circuit out there. We include a comparison to the circuit pointed out by @Sam Palmer here.

https://arxiv.org/abs/2210.11786

The full circuit description as well as how it works and how to us it is in the text but definitely happy to help out anybody looking to use it! Thanks everyone!

sheesymcdeezy
  • 2,041
  • 8
  • 27