<p dir="auto">The C function <code class="notranslate">malloc()</code> returns NULL (i.e. 0) if it fails to allocate memory.  The return value of a <code class="notranslate">malloc()</code> call must be checked for this value before attempting to use the result.  Here are places in the scipy code where this check is not made.  If any of these calls fails, the result is likely to be a segmentation fault.</p>
<p dir="auto"><strong>Cython</strong></p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">cluster</code><br>
In the file <code class="notranslate">_optimal_leaf_ordering.pyx</code>, in the function <code class="notranslate">identify_swaps</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">interpolate</code><br>
In the file <code class="notranslate">_ppoly.pyx</code>, in the functions <code class="notranslate">real_roots</code>, <code class="notranslate">croots_poly1</code> and <code class="notranslate">_croots_poly1</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">spatial</code><br>
In <code class="notranslate">setlist.pxd</code>, in the function <code class="notranslate">init</code>, in the statement <code class="notranslate">setlists.sets[j] = ...</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">sparse.csgraph</code><br>
File <code class="notranslate">_shortest_path.pyx</code>, in the code that creates <code class="notranslate">nodes</code> in the functions <code class="notranslate">_dijkstra_directed</code>, <code class="notranslate">_dijkstra_directed_multi</code>, <code class="notranslate">_dijkstra_undirected</code>, <code class="notranslate">_dijkstra_undirected_multi</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">_lib</code><br>
In the file <code class="notranslate">_ccallback_c.pyx</code>, the result of <code class="notranslate">strdup</code> is used without checking for NULL.  <code class="notranslate">strdup</code> can fail to allocate memory for the duplicated string.  In that case, it returns NULL.  (Note: this might be harmless.  I haven't checked to see if the pointer is ever dereferenced while the capsule is in use.)</li>
</ul>
<p dir="auto"><strong>C</strong></p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">fftpack</code><br>
In the file <code class="notranslate">fftpack.h</code>, the macro <code class="notranslate">GEN_CACHE</code> is defined.  It is used in the files <code class="notranslate">convolve.c</code>, <code class="notranslate">drfft.c</code>, <code class="notranslate">zfft.c</code>,<code class="notranslate">zfftnd.c</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">ndimage</code><br>
In the file <code class="notranslate">src/ni_morphology.c</code>, at line 624 (at the time of this writing): <code class="notranslate">temp-&gt;coordinates = malloc(...)</code></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <code class="notranslate">signal</code><br>
File <code class="notranslate">sigtoolsmodule.c</code>, lines 914--927 (8 unchecked calls to malloc) and line 1096</li>
</ul>
<hr>
<p dir="auto">We have vendored code in <code class="notranslate">sparse</code> and <code class="notranslate">spatial</code> that use <code class="notranslate">malloc</code>:</p>
<ul dir="auto">
<li>The SuperLU code in <code class="notranslate">linalg/dsolve/SuperLU/SRC</code> has its own memory management code. I didn't spend time trying to figure out the memory management here.  The file <code class="notranslate">cmemory.c</code> is the most relevant, and there appear to be calls to <code class="notranslate">intMalloc()</code> and <code class="notranslate">user_malloc()</code> that do not check for failure, but I didn't dig deeper to see if those functions check for failure before returning.</li>
<li><code class="notranslate">spatial</code> provides a wrapper for QHull.  I didn't look very deeply into how the qhull code manages memory. It looks like the function <code class="notranslate">qh_memalloc()</code> in <code class="notranslate">mem_r.c</code> will print an error and exit if it fails.</li>
</ul>
<p dir="auto">We should be aware of these vendored packages using malloc, but I think a thorough review of their memory management is not required.  Someone can do a deep dive into either of these libraries in the future if there is ever a suspicion that they are leaking memory.</p>
<p dir="auto">My issue is about the error LinAlgError: Schur form not found. Possibly ill-conditioned raised when I use the following code. The problem is that it only happens in the first execution of the script, then it disappears. It also happens when I try to use <code class="notranslate">scipy.linalg.expm</code> and <code class="notranslate">scipy.linalg.logm</code> as it has to do with the Schur decomposition.</p>
<h4 dir="auto">Reproducing code example:</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
&quot;&quot;&quot; Obtains the fidelity for the QFT for n=3 for Qiskit noise model &quot;&quot;&quot;

import numpy as np

def fidelity(a,b):
    ''' Computes the fidelity of two density matrices
    
    Args:
        a (array): density  matrix
        b (array): density matrix
    
    Returns:
        float: fidelity of a and b
        '''
    return (np.matrix.trace(scipy.linalg.sqrtm(np.matmul(scipy.linalg.sqrtm(a),np.matmul(b,scipy.linalg.sqrtm(a))))))**2

rho0=np.array([[0.23394436+0.j        , 0.11036513+0.07068888j,
        0.03302341+0.1088189j , 0.02706909+0.0881958j ,
        0.05815633-0.01072523j, 0.02037557-0.02607218j,
        0.1016744 +0.00529989j, 0.12719727+0.00524902j],
       [0.11036513-0.07068888j, 0.13571167+0.j        ,
        0.05817668+0.06459554j, 0.05001153+0.03409153j,
        0.01467896-0.03614299j, 0.02297974-0.02354262j,
        0.05975342-0.05200195j, 0.07036336-0.04786174j],
       [0.03302341-0.1088189j , 0.05817668-0.06459554j,
        0.14170668+0.j        , 0.09006076-0.00379435j,
        0.0081075 -0.02009074j, 0.00140381-0.01287842j,
        0.01685588-0.05481296j, 0.02995809-0.0568339j ],
       [0.02706909-0.0881958j , 0.05001153-0.03409153j,
        0.09006076+0.00379435j, 0.1104499 +0.j        ,
        0.0189209 -0.01251221j, 0.00768026-0.02039591j,
        0.03121948-0.0254008j , 0.03673299-0.03857761j],
       [0.05815633+0.01072523j, 0.01467896+0.03614299j,
        0.0081075 +0.02009074j, 0.0189209 +0.01251221j,
        0.0863071 +0.j        , 0.04125298+0.00418091j,
        0.01762221-0.00102403j, 0.03347778+0.00219727j],
       [0.02037557+0.02607218j, 0.02297974+0.02354262j,
        0.00140381+0.01287842j, 0.00768026+0.02039591j,
        0.04125298-0.00418091j, 0.06473456+0.j        ,
        0.0410258 +0.00813802j, 0.01971775+0.01372613j],
       [0.1016744 -0.00529989j, 0.05975342+0.05200195j,
        0.01685588+0.05481296j, 0.03121948+0.0254008j ,
        0.01762221+0.00102403j, 0.0410258 -0.00813802j,
        0.11333211+0.j        , 0.06110975+0.02015177j],
       [0.12719727-0.00524902j, 0.07036336+0.04786174j,
        0.02995809+0.0568339j , 0.03673299+0.03857761j,
        0.03347778-0.00219727j, 0.01971775-0.01372613j,
        0.06110975-0.02015177j, 0.11381361+0.j        ]])

rho=np.array([[ 0.17706638+0.j        ,  0.06659953+0.01608955j,
         0.0297682 +0.01830716j,  0.00812785+0.01222738j,
         0.00753445-0.00309584j,  0.00878906-0.01509603j,
         0.02885946-0.0179952j ,  0.04318237-0.01519775j],
       [ 0.06659953-0.01608955j,  0.13491143+0.j        ,
         0.03180949+0.01096598j,  0.01931085+0.01529609j,
         0.00876872-0.00343831j,  0.00969103-0.01005385j,
         0.01644897-0.02258301j,  0.02629598-0.01775106j],
       [ 0.0297682 -0.01830716j,  0.03180949-0.01096598j,
         0.12190416+0.j        ,  0.03262329+0.01110501j,
         0.0140686 -0.00460815j,  0.00094604-0.01165771j,
         0.00431993-0.02871026j,  0.01617432-0.02577718j],
       [ 0.00812785-0.01222738j,  0.01931085-0.01529609j,
         0.03262329-0.01110501j,  0.10249498+0.j        ,
         0.00314331-0.00964355j,  0.00564575+0.00064087j,
        -0.00264486-0.00935872j,  0.00440131-0.01796807j],
       [ 0.00753445+0.00309584j,  0.00876872+0.00343831j,
         0.0140686 +0.00460815j,  0.00314331+0.00964355j,
         0.10799493+0.j        ,  0.02676392+0.0035163j ,
         0.01410251+0.00034248j,  0.00727336+0.00429281j],
       [ 0.00878906+0.01509603j,  0.00969103+0.01005385j,
         0.00094604+0.01165771j,  0.00564575-0.00064087j,
         0.02676392-0.0035163j ,  0.10673353+0.j        ,
         0.01838175+0.00315348j,  0.02171156+0.01295641j],
       [ 0.02885946+0.0179952j ,  0.01644897+0.02258301j,
         0.00431993+0.02871026j, -0.00264486+0.00935872j,
         0.01410251-0.00034248j,  0.01838175-0.00315348j,
         0.12371487+0.j        ,  0.0449117 +0.01037259j],
       [ 0.04318237+0.01519775j,  0.02629598+0.01775106j,
         0.01617432+0.02577718j,  0.00440131+0.01796807j,
         0.00727336-0.00429281j,  0.02171156-0.01295641j,
         0.0449117 -0.01037259j,  0.12517971+0.j        ]])
fidelity=DAQC.fidelity(rho0,rho)
"><pre class="notranslate"><span class="pl-s">""" Obtains the fidelity for the QFT for n=3 for Qiskit noise model """</span>

<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-k">def</span> <span class="pl-en">fidelity</span>(<span class="pl-s1">a</span>,<span class="pl-s1">b</span>):
    <span class="pl-s">''' Computes the fidelity of two density matrices</span>
<span class="pl-s">    </span>
<span class="pl-s">    Args:</span>
<span class="pl-s">        a (array): density  matrix</span>
<span class="pl-s">        b (array): density matrix</span>
<span class="pl-s">    </span>
<span class="pl-s">    Returns:</span>
<span class="pl-s">        float: fidelity of a and b</span>
<span class="pl-s">        '''</span>
    <span class="pl-k">return</span> (<span class="pl-s1">np</span>.<span class="pl-s1">matrix</span>.<span class="pl-en">trace</span>(<span class="pl-s1">scipy</span>.<span class="pl-s1">linalg</span>.<span class="pl-en">sqrtm</span>(<span class="pl-s1">np</span>.<span class="pl-en">matmul</span>(<span class="pl-s1">scipy</span>.<span class="pl-s1">linalg</span>.<span class="pl-en">sqrtm</span>(<span class="pl-s1">a</span>),<span class="pl-s1">np</span>.<span class="pl-en">matmul</span>(<span class="pl-s1">b</span>,<span class="pl-s1">scipy</span>.<span class="pl-s1">linalg</span>.<span class="pl-en">sqrtm</span>(<span class="pl-s1">a</span>))))))<span class="pl-c1">**</span><span class="pl-c1">2</span>

<span class="pl-s1">rho0</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">0.23394436</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        , <span class="pl-c1">0.11036513</span><span class="pl-c1">+</span><span class="pl-c1">0.07068888j</span>,
        <span class="pl-c1">0.03302341</span><span class="pl-c1">+</span><span class="pl-c1">0.1088189j</span> , <span class="pl-c1">0.02706909</span><span class="pl-c1">+</span><span class="pl-c1">0.0881958j</span> ,
        <span class="pl-c1">0.05815633</span><span class="pl-c1">-</span><span class="pl-c1">0.01072523j</span>, <span class="pl-c1">0.02037557</span><span class="pl-c1">-</span><span class="pl-c1">0.02607218j</span>,
        <span class="pl-c1">0.1016744</span> <span class="pl-c1">+</span><span class="pl-c1">0.00529989j</span>, <span class="pl-c1">0.12719727</span><span class="pl-c1">+</span><span class="pl-c1">0.00524902j</span>],
       [<span class="pl-c1">0.11036513</span><span class="pl-c1">-</span><span class="pl-c1">0.07068888j</span>, <span class="pl-c1">0.13571167</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
        <span class="pl-c1">0.05817668</span><span class="pl-c1">+</span><span class="pl-c1">0.06459554j</span>, <span class="pl-c1">0.05001153</span><span class="pl-c1">+</span><span class="pl-c1">0.03409153j</span>,
        <span class="pl-c1">0.01467896</span><span class="pl-c1">-</span><span class="pl-c1">0.03614299j</span>, <span class="pl-c1">0.02297974</span><span class="pl-c1">-</span><span class="pl-c1">0.02354262j</span>,
        <span class="pl-c1">0.05975342</span><span class="pl-c1">-</span><span class="pl-c1">0.05200195j</span>, <span class="pl-c1">0.07036336</span><span class="pl-c1">-</span><span class="pl-c1">0.04786174j</span>],
       [<span class="pl-c1">0.03302341</span><span class="pl-c1">-</span><span class="pl-c1">0.1088189j</span> , <span class="pl-c1">0.05817668</span><span class="pl-c1">-</span><span class="pl-c1">0.06459554j</span>,
        <span class="pl-c1">0.14170668</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        , <span class="pl-c1">0.09006076</span><span class="pl-c1">-</span><span class="pl-c1">0.00379435j</span>,
        <span class="pl-c1">0.0081075</span> <span class="pl-c1">-</span><span class="pl-c1">0.02009074j</span>, <span class="pl-c1">0.00140381</span><span class="pl-c1">-</span><span class="pl-c1">0.01287842j</span>,
        <span class="pl-c1">0.01685588</span><span class="pl-c1">-</span><span class="pl-c1">0.05481296j</span>, <span class="pl-c1">0.02995809</span><span class="pl-c1">-</span><span class="pl-c1">0.0568339j</span> ],
       [<span class="pl-c1">0.02706909</span><span class="pl-c1">-</span><span class="pl-c1">0.0881958j</span> , <span class="pl-c1">0.05001153</span><span class="pl-c1">-</span><span class="pl-c1">0.03409153j</span>,
        <span class="pl-c1">0.09006076</span><span class="pl-c1">+</span><span class="pl-c1">0.00379435j</span>, <span class="pl-c1">0.1104499</span> <span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
        <span class="pl-c1">0.0189209</span> <span class="pl-c1">-</span><span class="pl-c1">0.01251221j</span>, <span class="pl-c1">0.00768026</span><span class="pl-c1">-</span><span class="pl-c1">0.02039591j</span>,
        <span class="pl-c1">0.03121948</span><span class="pl-c1">-</span><span class="pl-c1">0.0254008j</span> , <span class="pl-c1">0.03673299</span><span class="pl-c1">-</span><span class="pl-c1">0.03857761j</span>],
       [<span class="pl-c1">0.05815633</span><span class="pl-c1">+</span><span class="pl-c1">0.01072523j</span>, <span class="pl-c1">0.01467896</span><span class="pl-c1">+</span><span class="pl-c1">0.03614299j</span>,
        <span class="pl-c1">0.0081075</span> <span class="pl-c1">+</span><span class="pl-c1">0.02009074j</span>, <span class="pl-c1">0.0189209</span> <span class="pl-c1">+</span><span class="pl-c1">0.01251221j</span>,
        <span class="pl-c1">0.0863071</span> <span class="pl-c1">+</span><span class="pl-c1">0.j</span>        , <span class="pl-c1">0.04125298</span><span class="pl-c1">+</span><span class="pl-c1">0.00418091j</span>,
        <span class="pl-c1">0.01762221</span><span class="pl-c1">-</span><span class="pl-c1">0.00102403j</span>, <span class="pl-c1">0.03347778</span><span class="pl-c1">+</span><span class="pl-c1">0.00219727j</span>],
       [<span class="pl-c1">0.02037557</span><span class="pl-c1">+</span><span class="pl-c1">0.02607218j</span>, <span class="pl-c1">0.02297974</span><span class="pl-c1">+</span><span class="pl-c1">0.02354262j</span>,
        <span class="pl-c1">0.00140381</span><span class="pl-c1">+</span><span class="pl-c1">0.01287842j</span>, <span class="pl-c1">0.00768026</span><span class="pl-c1">+</span><span class="pl-c1">0.02039591j</span>,
        <span class="pl-c1">0.04125298</span><span class="pl-c1">-</span><span class="pl-c1">0.00418091j</span>, <span class="pl-c1">0.06473456</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
        <span class="pl-c1">0.0410258</span> <span class="pl-c1">+</span><span class="pl-c1">0.00813802j</span>, <span class="pl-c1">0.01971775</span><span class="pl-c1">+</span><span class="pl-c1">0.01372613j</span>],
       [<span class="pl-c1">0.1016744</span> <span class="pl-c1">-</span><span class="pl-c1">0.00529989j</span>, <span class="pl-c1">0.05975342</span><span class="pl-c1">+</span><span class="pl-c1">0.05200195j</span>,
        <span class="pl-c1">0.01685588</span><span class="pl-c1">+</span><span class="pl-c1">0.05481296j</span>, <span class="pl-c1">0.03121948</span><span class="pl-c1">+</span><span class="pl-c1">0.0254008j</span> ,
        <span class="pl-c1">0.01762221</span><span class="pl-c1">+</span><span class="pl-c1">0.00102403j</span>, <span class="pl-c1">0.0410258</span> <span class="pl-c1">-</span><span class="pl-c1">0.00813802j</span>,
        <span class="pl-c1">0.11333211</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        , <span class="pl-c1">0.06110975</span><span class="pl-c1">+</span><span class="pl-c1">0.02015177j</span>],
       [<span class="pl-c1">0.12719727</span><span class="pl-c1">-</span><span class="pl-c1">0.00524902j</span>, <span class="pl-c1">0.07036336</span><span class="pl-c1">+</span><span class="pl-c1">0.04786174j</span>,
        <span class="pl-c1">0.02995809</span><span class="pl-c1">+</span><span class="pl-c1">0.0568339j</span> , <span class="pl-c1">0.03673299</span><span class="pl-c1">+</span><span class="pl-c1">0.03857761j</span>,
        <span class="pl-c1">0.03347778</span><span class="pl-c1">-</span><span class="pl-c1">0.00219727j</span>, <span class="pl-c1">0.01971775</span><span class="pl-c1">-</span><span class="pl-c1">0.01372613j</span>,
        <span class="pl-c1">0.06110975</span><span class="pl-c1">-</span><span class="pl-c1">0.02015177j</span>, <span class="pl-c1">0.11381361</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ]])

<span class="pl-s1">rho</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([[ <span class="pl-c1">0.17706638</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,  <span class="pl-c1">0.06659953</span><span class="pl-c1">+</span><span class="pl-c1">0.01608955j</span>,
         <span class="pl-c1">0.0297682</span> <span class="pl-c1">+</span><span class="pl-c1">0.01830716j</span>,  <span class="pl-c1">0.00812785</span><span class="pl-c1">+</span><span class="pl-c1">0.01222738j</span>,
         <span class="pl-c1">0.00753445</span><span class="pl-c1">-</span><span class="pl-c1">0.00309584j</span>,  <span class="pl-c1">0.00878906</span><span class="pl-c1">-</span><span class="pl-c1">0.01509603j</span>,
         <span class="pl-c1">0.02885946</span><span class="pl-c1">-</span><span class="pl-c1">0.0179952j</span> ,  <span class="pl-c1">0.04318237</span><span class="pl-c1">-</span><span class="pl-c1">0.01519775j</span>],
       [ <span class="pl-c1">0.06659953</span><span class="pl-c1">-</span><span class="pl-c1">0.01608955j</span>,  <span class="pl-c1">0.13491143</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
         <span class="pl-c1">0.03180949</span><span class="pl-c1">+</span><span class="pl-c1">0.01096598j</span>,  <span class="pl-c1">0.01931085</span><span class="pl-c1">+</span><span class="pl-c1">0.01529609j</span>,
         <span class="pl-c1">0.00876872</span><span class="pl-c1">-</span><span class="pl-c1">0.00343831j</span>,  <span class="pl-c1">0.00969103</span><span class="pl-c1">-</span><span class="pl-c1">0.01005385j</span>,
         <span class="pl-c1">0.01644897</span><span class="pl-c1">-</span><span class="pl-c1">0.02258301j</span>,  <span class="pl-c1">0.02629598</span><span class="pl-c1">-</span><span class="pl-c1">0.01775106j</span>],
       [ <span class="pl-c1">0.0297682</span> <span class="pl-c1">-</span><span class="pl-c1">0.01830716j</span>,  <span class="pl-c1">0.03180949</span><span class="pl-c1">-</span><span class="pl-c1">0.01096598j</span>,
         <span class="pl-c1">0.12190416</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,  <span class="pl-c1">0.03262329</span><span class="pl-c1">+</span><span class="pl-c1">0.01110501j</span>,
         <span class="pl-c1">0.0140686</span> <span class="pl-c1">-</span><span class="pl-c1">0.00460815j</span>,  <span class="pl-c1">0.00094604</span><span class="pl-c1">-</span><span class="pl-c1">0.01165771j</span>,
         <span class="pl-c1">0.00431993</span><span class="pl-c1">-</span><span class="pl-c1">0.02871026j</span>,  <span class="pl-c1">0.01617432</span><span class="pl-c1">-</span><span class="pl-c1">0.02577718j</span>],
       [ <span class="pl-c1">0.00812785</span><span class="pl-c1">-</span><span class="pl-c1">0.01222738j</span>,  <span class="pl-c1">0.01931085</span><span class="pl-c1">-</span><span class="pl-c1">0.01529609j</span>,
         <span class="pl-c1">0.03262329</span><span class="pl-c1">-</span><span class="pl-c1">0.01110501j</span>,  <span class="pl-c1">0.10249498</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
         <span class="pl-c1">0.00314331</span><span class="pl-c1">-</span><span class="pl-c1">0.00964355j</span>,  <span class="pl-c1">0.00564575</span><span class="pl-c1">+</span><span class="pl-c1">0.00064087j</span>,
        <span class="pl-c1">-</span><span class="pl-c1">0.00264486</span><span class="pl-c1">-</span><span class="pl-c1">0.00935872j</span>,  <span class="pl-c1">0.00440131</span><span class="pl-c1">-</span><span class="pl-c1">0.01796807j</span>],
       [ <span class="pl-c1">0.00753445</span><span class="pl-c1">+</span><span class="pl-c1">0.00309584j</span>,  <span class="pl-c1">0.00876872</span><span class="pl-c1">+</span><span class="pl-c1">0.00343831j</span>,
         <span class="pl-c1">0.0140686</span> <span class="pl-c1">+</span><span class="pl-c1">0.00460815j</span>,  <span class="pl-c1">0.00314331</span><span class="pl-c1">+</span><span class="pl-c1">0.00964355j</span>,
         <span class="pl-c1">0.10799493</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,  <span class="pl-c1">0.02676392</span><span class="pl-c1">+</span><span class="pl-c1">0.0035163j</span> ,
         <span class="pl-c1">0.01410251</span><span class="pl-c1">+</span><span class="pl-c1">0.00034248j</span>,  <span class="pl-c1">0.00727336</span><span class="pl-c1">+</span><span class="pl-c1">0.00429281j</span>],
       [ <span class="pl-c1">0.00878906</span><span class="pl-c1">+</span><span class="pl-c1">0.01509603j</span>,  <span class="pl-c1">0.00969103</span><span class="pl-c1">+</span><span class="pl-c1">0.01005385j</span>,
         <span class="pl-c1">0.00094604</span><span class="pl-c1">+</span><span class="pl-c1">0.01165771j</span>,  <span class="pl-c1">0.00564575</span><span class="pl-c1">-</span><span class="pl-c1">0.00064087j</span>,
         <span class="pl-c1">0.02676392</span><span class="pl-c1">-</span><span class="pl-c1">0.0035163j</span> ,  <span class="pl-c1">0.10673353</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,
         <span class="pl-c1">0.01838175</span><span class="pl-c1">+</span><span class="pl-c1">0.00315348j</span>,  <span class="pl-c1">0.02171156</span><span class="pl-c1">+</span><span class="pl-c1">0.01295641j</span>],
       [ <span class="pl-c1">0.02885946</span><span class="pl-c1">+</span><span class="pl-c1">0.0179952j</span> ,  <span class="pl-c1">0.01644897</span><span class="pl-c1">+</span><span class="pl-c1">0.02258301j</span>,
         <span class="pl-c1">0.00431993</span><span class="pl-c1">+</span><span class="pl-c1">0.02871026j</span>, <span class="pl-c1">-</span><span class="pl-c1">0.00264486</span><span class="pl-c1">+</span><span class="pl-c1">0.00935872j</span>,
         <span class="pl-c1">0.01410251</span><span class="pl-c1">-</span><span class="pl-c1">0.00034248j</span>,  <span class="pl-c1">0.01838175</span><span class="pl-c1">-</span><span class="pl-c1">0.00315348j</span>,
         <span class="pl-c1">0.12371487</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ,  <span class="pl-c1">0.0449117</span> <span class="pl-c1">+</span><span class="pl-c1">0.01037259j</span>],
       [ <span class="pl-c1">0.04318237</span><span class="pl-c1">+</span><span class="pl-c1">0.01519775j</span>,  <span class="pl-c1">0.02629598</span><span class="pl-c1">+</span><span class="pl-c1">0.01775106j</span>,
         <span class="pl-c1">0.01617432</span><span class="pl-c1">+</span><span class="pl-c1">0.02577718j</span>,  <span class="pl-c1">0.00440131</span><span class="pl-c1">+</span><span class="pl-c1">0.01796807j</span>,
         <span class="pl-c1">0.00727336</span><span class="pl-c1">-</span><span class="pl-c1">0.00429281j</span>,  <span class="pl-c1">0.02171156</span><span class="pl-c1">-</span><span class="pl-c1">0.01295641j</span>,
         <span class="pl-c1">0.0449117</span> <span class="pl-c1">-</span><span class="pl-c1">0.01037259j</span>,  <span class="pl-c1">0.12517971</span><span class="pl-c1">+</span><span class="pl-c1">0.j</span>        ]])
<span class="pl-s1">fidelity</span><span class="pl-c1">=</span><span class="pl-v">DAQC</span>.<span class="pl-en">fidelity</span>(<span class="pl-s1">rho0</span>,<span class="pl-s1">rho</span>)</pre></div>
<h4 dir="auto">Error message:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="File &quot;C:\Users\Paula\Dropbox\Master thesis\FinalCode\ibmq_estimation\DAQC.py&quot;, line 37, in fidelity
    return (np.matrix.trace(scipy.linalg.sqrtm(np.matmul(scipy.linalg.sqrtm(a),np.matmul(b,scipy.linalg.sqrtm(a))))))**2

  File &quot;C:\Users\Paula\Anaconda3\envs\test_env\lib\site-packages\scipy\linalg\_matfuncs_sqrtm.py&quot;, line 172, in sqrtm
    T, Z = schur(A, output='complex')

  File &quot;C:\Users\Paula\Anaconda3\envs\test_env\lib\site-packages\scipy\linalg\decomp_schur.py&quot;, line 170, in schur
    raise LinAlgError(&quot;Schur form not found. Possibly ill-conditioned.&quot;)

LinAlgError: Schur form not found. Possibly ill-conditioned.
  ..."><pre class="notranslate"><code class="notranslate">File "C:\Users\Paula\Dropbox\Master thesis\FinalCode\ibmq_estimation\DAQC.py", line 37, in fidelity
    return (np.matrix.trace(scipy.linalg.sqrtm(np.matmul(scipy.linalg.sqrtm(a),np.matmul(b,scipy.linalg.sqrtm(a))))))**2

  File "C:\Users\Paula\Anaconda3\envs\test_env\lib\site-packages\scipy\linalg\_matfuncs_sqrtm.py", line 172, in sqrtm
    T, Z = schur(A, output='complex')

  File "C:\Users\Paula\Anaconda3\envs\test_env\lib\site-packages\scipy\linalg\decomp_schur.py", line 170, in schur
    raise LinAlgError("Schur form not found. Possibly ill-conditioned.")

LinAlgError: Schur form not found. Possibly ill-conditioned.
  ...
</code></pre></div>
<h4 dir="auto">Scipy/Numpy/Python version information:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)

1.5.2 1.18.5 sys.version_info(major=3, minor=7, micro=7, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)

1.5.2 1.18.5 sys.version_info(major=3, minor=7, micro=7, releaselevel='final', serial=0)
</code></pre></div>