Paclet Installation


Theory

In a previous post, we demonstrated the Variational Quantum Linear Solver (VQLS), a hybrid quantum-classical technique designed to solve Quantum Linear Systems Problems (QLSP). Simply put, it finds linear solutions for equations of the form ”
A.x=b
”.
We propose an Multiplexer–Based Variational Quantum Linear Solver (MB-VQLS). The primary distinctions between MB–VQLS and a conventional VQLS lie in two key aspects:
◼
  • The controlled implementation of the matrix
    A
    through a multiplexer, enabling the accurate representation of the operation
    A.x
    within the quantum circuit.
  • ◼
  • The solution to the linear system is encoded directly in the amplitudes of the resultant quantum state.
  • This approach simplifies the standard VQLS process of using multiple circuits for the real-imaginary decomposition of the solution and the termwise (term-by-term) computation in quantum circuits. A detailed step-by-step for this implementation is provided in this notebook.
    To summarize the problem statement, given:
    ◼
  • Problem vector b: Normalized quantum state
    |b〉.
  • ◼
  • Problem matrix A:
    n
    2
    x
    n
    2
    matrix such that
    A=
    L-1
    ∑
    0
    c
    l
    A
    l
    where
    c
    l
    ϵ
    and
    ||A||<=1
  • We pursue to prepare:
    ◼
  • A quantum state
    |x〉
    such that
    A|x〉=|
    ψ
    〉
    with
    
    b
    
    ψ
    
    2
    =1
  • For this, we will obtain approximated
    |x(ω)〉
    states through a variational quantum circuit
    V
    (ω):
    |x(ω)〉=V(ω)|0〉
    And we will be minimizing a cost function with
    ω={
    ω
    0
    ,
    ω
    1
    ,...}
    parameters to reach our goal:
    f(ω)=1-
    b
    
    ψ(ω)
    
    2
    Further steps will show that we can avoid some
    |b〉
    and
    A
    restrictions using their normalization terms. This would help us finding solutions for any system.
    In the following examples we won’t limit to solve simple Pauli system problems as previous posts, we will start right away with real and complex random
    b
    vectors and random
    A
    problem matrices.

    A.x
    Operation Circuit Representation

    For this section, we will follow the guide already published by the Wolfram Quantum Computation Framework Team.
    Considering an
    n
    x
    n
    A matrix and an
    n
    -element vector x, we look to compute the operation
    A.x
    with a quantum circuit using
    A
    as a controlled operation.
    Given:
    In[]:=
    x=RandomComplex[{-1-1*I,+1+1*I},4]
    Out[]=
    {-0.347991+0.931491,-0.0392888-0.0284354,0.103762+0.831308,-0.489936+0.6389}
    In[]:=
    a=RandomReal[{-1,1},{4,4}];​​a//MatrixForm
    Out[]//MatrixForm=
    0.798301
    0.574044
    0.915333
    0.202758
    -0.917779
    0.00718937
    -0.695192
    0.127807
    0.317395
    -0.307586
    0.0114712
    -0.391997
    -0.109567
    0.557948
    -0.228003
    -0.486929
    We proceed to generate a quantum operator
    A
    and decompose it in Pauli Matrices such that
    A=
    c
    j
    A
    j
    :
    In[]:=
    A=QuantumOperator[a];
    In[]:=
    pauliDecompose=A["PauliDecompose"]
    Out[]=
    XX-0.227397+0.,XY0.+0.174982,XZ0.136743+0.,XI0.479621+0.,YX0.-0.0188202,YY-0.273992+0.,YZ0.+0.25702,YI0.+0.0419493,ZX0.0690661+0.,ZY0.+0.413954,ZZ0.0731779+0.,ZI0.320237+0.,IX-0.240934+0.,IY0.+0.331957,IZ0.322378+0.,II0.0825082+0.
    In order to implement the controlled A gates, we will turn the Pauli matrices as targets into a Multiplexer and the controlled qubits would be evaluated by a
    
    c
    
    state:
    In[]:=
    multiplexer=QuantumCircuitOperator["Multiplexer"@@Keys[pauliDecompose]];
    In[]:=
    ancillary=QuantumStateSqrt@Values[pauliDecompose],"Label"->"
    c
    ";
    Finally, we would let our vector
    x
    be evaluated by the multiplexer in our citcuit:
    In[]:=
    productCircuit=QuantumCircuitOperator​​ancillary,​​QuantumState[x,"Label"->"x"]->{5,6},​​multiplexer,​​
    †
    ancillary["Conjugate"]
    ​​;
    In[]:=
    productCircuit["Diagram",ImageSize->Full]
    Out[]=
    Evaluate our circuit and check the amplitudes of the resultant state:
    In[]:=
    productCircuit[]["AmplitudesList"]
    Out[]=
    {-0.304717+1.61775,0.184345-1.35137,0.0948776+0.0634864,0.231113-0.618566}
    The result correspond to the equivalent classical operation:
    In[]:=
    a.x
    Out[]=
    {-0.304717+1.61775,0.184345-1.35137,0.0948776+0.0634864,0.231113-0.618566}

    Quantum Linear Solver Implementation

    Now that we learned how to compute the product of a matrix and vector using a Quantum Circuit, we have a better understanding on how to implement our new variational quantum linear solver.
    Given a
    b
    problem vector and an
    A
    problem matrix, the basic steps are:
    ◼
  • Start with a variational circuit ansatz
    V(
    ω
    i
    )
    or state ansatz
    x(
    ω
    i
    )=V(
    ω
    i
    )|0〉
  • ◼
  • Apply the multiplexer such that we perform
    A.x(
    ω
    i
    )
    and obtain resultant
    ψ(
    ω
    i
    )
    state
  • ◼
  • Use
    ψ(
    ω
    i
    )
    state as input for the optimizer with the cost function
    f(ω)=1-
    b
    
    ψ(ω)
    
    2
    to obtain new
    ω
    j
    parameters
  • ◼
  • Use new
    ω
    j
    parameters with the variational circuit
    V(
    ω
    i
    )
    or state ansatz
    x(
    ω
    j
    )
  • ◼
  • Repeat the process until you obtain
    f(
    ω
    opt
    )=1-
    b
    
    ψ(
    ω
    opt
    )
    
    2
    =0
  • Initial problem setup
    

    Multiplexer implementation

    For this section we need to repeat what is stated in “
    A.x
    Operation Circuit Representation“ section.
    First, we need to decompose
    
    A
    in Pauli matrices such that
    
    A
    =∑
    c
    i
    A
    i
    :
    In[]:=
    pauliDecompose=QuantumOperator[matrixA/normA]["PauliDecompose"];
    In[]:=
    pauliDecompose
    Out[]=
    XX0.238307+0.,XY0.-0.0171748,XZ0.153066+0.,XI0.255368+0.,YX0.+0.0221491,YY0.167908+0.,YZ0.+0.0149763,YI0.+0.0309613,ZX0.0582089+0.,ZY0.-0.0975743,ZZ-0.0302903+0.,ZI0.00164333+0.,IX0.249554+0.,IY0.+0.0029762,IZ-0.109616+0.,II0.192193+0.
    Next, implement the multiplexer:
    multiplexer=QuantumCircuitOperator["Multiplexer"@@Keys[pauliDecompose]];
    In[]:=
    ancillary=QuantumStateSqrt@Values[pauliDecompose],"Label"->"
    c
    ";
    We obtain the first section of the variational circuit for the VQLS:
    In[]:=
    CircuitA=QuantumCircuitOperator​​ancillary,​​multiplexer,​​
    †
    (ancillary["Conjugate"])
    ​​;
    In[]:=
    CircuitA["Diagram",ImageSize->Full]
    Out[]=

    General Symbolic Ansatz

    Define a general state ansatz for 4-qubits with real amplitudes:
    Finally we implement the circuit and the correspondent state:
    Wolfram Quantum Framework quantum states (and measurements) keep the parameters defined in previously used circuits, so it would be optimum to work with the resultant state:

    Optimization

    In order to correct our result, we need to find the global phase and apply it once our calculation is done.

    Optimization using NMinimize

    Let’s optimize the cost function using NMinimize:
    As previously stated, while the probability distributions match, the amplitudes do not necessarily align:
    We can verify our result:

    Optimization using Quantum Natural Gradient Descent

    As explained in a previous example, we can optimize using QuantumNaturalGradientDescent calculating their correspondent Fubini-Study metric tensor:
    Check the evolution of the minimization using a simple plot:
    We can verify that the minimization approaches to 0.
    As previously stated, while the probability distributions match, the amplitudes do not necessarily align:
    We can verify our result approximation:

    QuantumLinearSolve Function

    The QuantumLinearSolve function is a new addition to the Wolfram Quantum Framework. It simplifies the process of solving linear systems with hybrid classical-quantum algorithms by condensing previous code into a single function.
    Use QuantumLinearSolve function to solve the linear system. This function will implement the necessary multiplexer and determine the optimal general ansatz state to solve the QLSP:
    Finally compare the results:
    Our result demonstrate a high degree of approximation accuracy:

    Properties

    It is possible to ask for every element used in the implementation indicating a property as third input:

    Scope & Method

    It is also possible to add multiple options for the minimization such as AccuracyGoal and PrecisionGoal:
    You can use multiple methods for the optimization which will display a progression plot:
    More about the properties, methods and functionalities of QuantumLinearSolve in the following documentation page:
    ​https://resources.wolframcloud.com/PacletRepository/resources/Wolfram/QuantumFramework/tutorial/ExampleRepositoryFunctions.html

    References

    ◼
  • Mads Bahrami (2024). Compute the Product of a Matrix and Vector using a Quantum Circuit. Wolfram Example Repository. https://resources.wolframcloud.com/ExampleRepository/resources/Coherent-applying-of-a-matrix-on-a-vector/
  • ◼
  • Bravo-Prieto, C., LaRose, R., Cerezo, M., Subasi, Y., Cincio, L., & Coles, P. J. (2019). Variational Quantum Linear Solver. arXiv. https://doi.org/10.48550/ARXIV.1909.05820
  • ◼
  • Mari, A. Variational Quantum Linear Solver. PennyLane Demos. https://pennylane.ai/qml/demos/tutorial_coherent_vqls/
  • CITE THIS NOTEBOOK

    Multiplexer-based variational quantum linear solver​
    by Sebastian Rodriguez​
    Wolfram Community, STAFF PICKS, August 22, 2024
    ​https://community.wolfram.com/groups/-/m/t/3253903