quest_bind 0.3.7

Wrapper around the Quantum Exact Simulation Toolkit (QuEST)
Documentation
<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.17"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>QuEST: Gates</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="style.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand"><img alt="Logo" src="logo.png"/></a>
                    <a class="navbar-brand"><b>QuEST</b> v3.4.0<br>The Quantum Exact Simulation Toolkit</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Gates</div>  </div>
</div><!--header-->
<div class="contents">

<p>Non-unitary but norm-preserving gates, such as measurements.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga34457f7f62ccd75fb7d3fe67cd2f815a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__normgate.html#ga34457f7f62ccd75fb7d3fe67cd2f815a">collapseToOutcome</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, int measureQubit, int outcome)</td></tr>
<tr class="memdesc:ga34457f7f62ccd75fb7d3fe67cd2f815a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Updates <code>qureg</code> to be consistent with measuring <code>measureQubit</code> in the given <code>outcome</code> (0 or 1), and returns the probability of such a measurement outcome.  <a href="group__normgate.html#ga34457f7f62ccd75fb7d3fe67cd2f815a">More...</a><br /></td></tr>
<tr class="separator:ga34457f7f62ccd75fb7d3fe67cd2f815a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2a3794103125f1e3cfa103f8b1963656"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__normgate.html#ga2a3794103125f1e3cfa103f8b1963656">measure</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, int measureQubit)</td></tr>
<tr class="memdesc:ga2a3794103125f1e3cfa103f8b1963656"><td class="mdescLeft">&#160;</td><td class="mdescRight">Measures a single qubit, collapsing it randomly to 0 or 1.  <a href="group__normgate.html#ga2a3794103125f1e3cfa103f8b1963656">More...</a><br /></td></tr>
<tr class="separator:ga2a3794103125f1e3cfa103f8b1963656"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae192ac0759e46c7b20a7182020155240"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__normgate.html#gae192ac0759e46c7b20a7182020155240">measureWithStats</a> (<a class="el" href="structQureg.html">Qureg</a> qureg, int measureQubit, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *outcomeProb)</td></tr>
<tr class="memdesc:gae192ac0759e46c7b20a7182020155240"><td class="mdescLeft">&#160;</td><td class="mdescRight">Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome.  <a href="group__normgate.html#gae192ac0759e46c7b20a7182020155240">More...</a><br /></td></tr>
<tr class="separator:gae192ac0759e46c7b20a7182020155240"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Non-unitary but norm-preserving gates, such as measurements. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga34457f7f62ccd75fb7d3fe67cd2f815a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga34457f7f62ccd75fb7d3fe67cd2f815a">&#9670;&nbsp;</a></span>collapseToOutcome()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> collapseToOutcome </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>measureQubit</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>outcome</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Updates <code>qureg</code> to be consistent with measuring <code>measureQubit</code> in the given <code>outcome</code> (0 or 1), and returns the probability of such a measurement outcome. </p>
<p>This is effectively performing a renormalising projection, or a measurement with a forced outcome. This is an irreversible change to the state, whereby computational states inconsistant with the outcome are given zero amplitude and the <code>qureg</code> is renormalised. The given outcome must not have a near zero probability, else it cannot be collapsed into.</p>
<p>Note that the collapse probably used for renormalisation is calculated for <code>outcome</code> <code>=</code> <code>0</code>, and assumed 1 minus this probability if <code>outcome</code> <code>=</code> <code>1</code>. Hence this routine will not correctly project un-normalised quregs onto <code>outcome</code> <code>=</code> <code>1</code>.</p>
<p>To avoid renormalisation after projection, or force projection into non-physical states with very small probability, use <a class="el" href="group__operator.html#ga26db8b8a8a242d388c291e50d228ab18" title="Force the target qubit of qureg into the given classical outcome, via a non-renormalising projection.">applyProjector()</a>.</p>
<dl class="section see"><dt>See also</dt><dd><ul>
<li><a class="el" href="group__normgate.html#ga2a3794103125f1e3cfa103f8b1963656" title="Measures a single qubit, collapsing it randomly to 0 or 1.">measure()</a></li>
<li><a class="el" href="group__normgate.html#gae192ac0759e46c7b20a7182020155240" title="Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of ...">measureWithStats()</a></li>
<li><a class="el" href="group__operator.html#ga26db8b8a8a242d388c291e50d228ab18" title="Force the target qubit of qureg into the given classical outcome, via a non-renormalising projection.">applyProjector()</a></li>
</ul>
</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>object representing the set of all qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">measureQubit</td><td>qubit to measure </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">outcome</td><td>to force the measure qubit to enter </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>probability of the (forced) measurement outcome </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="group__debug.html#ga51a64b05d31ef9bcf6a63ce26c0092db" title="An internal function called when invalid arguments are passed to a QuEST API call,...">invalidQuESTInputError()</a></td><td><ul>
<li>if <code>measureQubit</code> is outside [0, <code>qureg.numQubitsRepresented</code>)</li>
<li>if <code>outcome</code> is not in {0, 1}</li>
<li>if the probability of <code>outcome</code> is zero (within machine epsilon) </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00966">966</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00966"></a><span class="lineno">  966</span>&#160;                                                                    {</div>
<div class="line"><a name="l00967"></a><span class="lineno">  967</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a>(qureg, measureQubit, __func__);</div>
<div class="line"><a name="l00968"></a><span class="lineno">  968</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ad613c75ff252a88e54f911053bd2032c">validateOutcome</a>(outcome, __func__);</div>
<div class="line"><a name="l00969"></a><span class="lineno">  969</span>&#160;    </div>
<div class="line"><a name="l00970"></a><span class="lineno">  970</span>&#160;    <a class="code" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> outcomeProb;</div>
<div class="line"><a name="l00971"></a><span class="lineno">  971</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>) {</div>
<div class="line"><a name="l00972"></a><span class="lineno">  972</span>&#160;        outcomeProb = <a class="code" href="QuEST__internal_8h.html#ae37b3eff5d3affbc1edfe216cabc1c53">densmatr_calcProbOfOutcome</a>(qureg, measureQubit, outcome);</div>
<div class="line"><a name="l00973"></a><span class="lineno">  973</span>&#160;        <a class="code" href="QuEST__validation_8c.html#a8accabb8a9d573c2ff80305841c3053d">validateMeasurementProb</a>(outcomeProb, __func__);</div>
<div class="line"><a name="l00974"></a><span class="lineno">  974</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a5658f2ecbbd4ea425db5f7dc7fc4ba92">densmatr_collapseToKnownProbOutcome</a>(qureg, measureQubit, outcome, outcomeProb);</div>
<div class="line"><a name="l00975"></a><span class="lineno">  975</span>&#160;    } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00976"></a><span class="lineno">  976</span>&#160;        outcomeProb = <a class="code" href="QuEST__internal_8h.html#a63cb88a5f4eb12fef087435b8db3f8eb">statevec_calcProbOfOutcome</a>(qureg, measureQubit, outcome);</div>
<div class="line"><a name="l00977"></a><span class="lineno">  977</span>&#160;        <a class="code" href="QuEST__validation_8c.html#a8accabb8a9d573c2ff80305841c3053d">validateMeasurementProb</a>(outcomeProb, __func__);</div>
<div class="line"><a name="l00978"></a><span class="lineno">  978</span>&#160;        <a class="code" href="QuEST__internal_8h.html#a008becc4a18f868340836e0ab9fd6df6">statevec_collapseToKnownProbOutcome</a>(qureg, measureQubit, outcome, outcomeProb);</div>
<div class="line"><a name="l00979"></a><span class="lineno">  979</span>&#160;    }</div>
<div class="line"><a name="l00980"></a><span class="lineno">  980</span>&#160;    </div>
<div class="line"><a name="l00981"></a><span class="lineno">  981</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a0befde437a58ef8fe38495bfc2a16f0e">qasm_recordMeasurement</a>(qureg, measureQubit);</div>
<div class="line"><a name="l00982"></a><span class="lineno">  982</span>&#160;    <span class="keywordflow">return</span> outcomeProb;</div>
<div class="line"><a name="l00983"></a><span class="lineno">  983</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01328">densmatr_calcProbOfOutcome()</a>, <a class="el" href="QuEST__cpu_8c_source.html#l00791">densmatr_collapseToKnownProbOutcome()</a>, <a class="el" href="QuEST_8h_source.html#l00325">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00411">qasm_recordMeasurement()</a>, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01312">statevec_calcProbOfOutcome()</a>, <a class="el" href="QuEST__cpu__distributed_8c_source.html#l01368">statevec_collapseToKnownProbOutcome()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00527">validateMeasurementProb()</a>, <a class="el" href="QuEST__validation_8c_source.html#l00523">validateOutcome()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00400">validateTarget()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__gates_8cpp_source.html#l00015">TEST_CASE()</a>.</p>

</div>
</div>
<a id="ga2a3794103125f1e3cfa103f8b1963656"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2a3794103125f1e3cfa103f8b1963656">&#9670;&nbsp;</a></span>measure()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int measure </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>measureQubit</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Measures a single qubit, collapsing it randomly to 0 or 1. </p>
<p>Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.</p>
<blockquote class="doxtable">
<p>The random outcome generator is seeded by <a class="el" href="group__debug.html#gae53fad7ebafccf236ad62b41e3244214" title="Seeds the random number generator with the (master node) current time and process ID.">seedQuESTDefault()</a> within <a class="el" href="group__type.html#ga8ba2c3388dd64d9348c3b091852d36d4" title="Create the QuEST execution environment.">createQuESTEnv()</a>, unless later overridden by <a class="el" href="group__debug.html#ga555451c697ea4a9d27389155f68fdabc" title="Seeds the random number generator with a custom array of key(s), overriding the default keys.">seedQuEST()</a>. </p>
</blockquote>
<dl class="section see"><dt>See also</dt><dd><ul>
<li><a class="el" href="group__normgate.html#gae192ac0759e46c7b20a7182020155240" title="Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of ...">measureWithStats()</a></li>
<li><a class="el" href="group__normgate.html#ga34457f7f62ccd75fb7d3fe67cd2f815a" title="Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...">collapseToOutcome()</a></li>
<li><a class="el" href="group__debug.html#ga555451c697ea4a9d27389155f68fdabc" title="Seeds the random number generator with a custom array of key(s), overriding the default keys.">seedQuEST()</a></li>
<li><a class="el" href="group__debug.html#gae53fad7ebafccf236ad62b41e3244214" title="Seeds the random number generator with the (master node) current time and process ID.">seedQuESTDefault()</a></li>
</ul>
</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>object representing the set of all qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">measureQubit</td><td>qubit to measure </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the measurement outcome, 0 or 1 </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="group__debug.html#ga51a64b05d31ef9bcf6a63ce26c0092db" title="An internal function called when invalid arguments are passed to a QuEST API call,...">invalidQuESTInputError()</a></td><td><ul>
<li>if <code>measureQubit</code> is outside [0, <code>qureg.numQubitsRepresented</code>) </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00998">998</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00998"></a><span class="lineno">  998</span>&#160;                                           {</div>
<div class="line"><a name="l00999"></a><span class="lineno">  999</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a>(qureg, measureQubit, __func__);</div>
<div class="line"><a name="l01000"></a><span class="lineno"> 1000</span>&#160;    </div>
<div class="line"><a name="l01001"></a><span class="lineno"> 1001</span>&#160;    <span class="keywordtype">int</span> outcome;</div>
<div class="line"><a name="l01002"></a><span class="lineno"> 1002</span>&#160;    <a class="code" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> discardedProb;</div>
<div class="line"><a name="l01003"></a><span class="lineno"> 1003</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l01004"></a><span class="lineno"> 1004</span>&#160;        outcome = <a class="code" href="QuEST__common_8c.html#ae4ebc1f4dd48922bfb30ad1692310269">densmatr_measureWithStats</a>(qureg, measureQubit, &amp;discardedProb);</div>
<div class="line"><a name="l01005"></a><span class="lineno"> 1005</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l01006"></a><span class="lineno"> 1006</span>&#160;        outcome = <a class="code" href="QuEST__common_8c.html#ac2eb81c71d0e0fbec7be5b45b1db1448">statevec_measureWithStats</a>(qureg, measureQubit, &amp;discardedProb);</div>
<div class="line"><a name="l01007"></a><span class="lineno"> 1007</span>&#160;    </div>
<div class="line"><a name="l01008"></a><span class="lineno"> 1008</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a0befde437a58ef8fe38495bfc2a16f0e">qasm_recordMeasurement</a>(qureg, measureQubit);</div>
<div class="line"><a name="l01009"></a><span class="lineno"> 1009</span>&#160;    <span class="keywordflow">return</span> outcome;</div>
<div class="line"><a name="l01010"></a><span class="lineno"> 1010</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__common_8c_source.html#l00372">densmatr_measureWithStats()</a>, <a class="el" href="QuEST_8h_source.html#l00325">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00411">qasm_recordMeasurement()</a>, <a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a>, <a class="el" href="QuEST__common_8c_source.html#l00364">statevec_measureWithStats()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00400">validateTarget()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__gates_8cpp_source.html#l00121">TEST_CASE()</a>.</p>

</div>
</div>
<a id="gae192ac0759e46c7b20a7182020155240"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae192ac0759e46c7b20a7182020155240">&#9670;&nbsp;</a></span>measureWithStats()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int measureWithStats </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structQureg.html">Qureg</a>&#160;</td>
          <td class="paramname"><em>qureg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>measureQubit</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a> *&#160;</td>
          <td class="paramname"><em>outcomeProb</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome. </p>
<p>Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.</p>
<blockquote class="doxtable">
<p>The random outcome generator is seeded by <a class="el" href="group__debug.html#gae53fad7ebafccf236ad62b41e3244214" title="Seeds the random number generator with the (master node) current time and process ID.">seedQuESTDefault()</a> within <a class="el" href="group__type.html#ga8ba2c3388dd64d9348c3b091852d36d4" title="Create the QuEST execution environment.">createQuESTEnv()</a>, unless later overridden by <a class="el" href="group__debug.html#ga555451c697ea4a9d27389155f68fdabc" title="Seeds the random number generator with a custom array of key(s), overriding the default keys.">seedQuEST()</a>. </p>
</blockquote>
<dl class="section see"><dt>See also</dt><dd><ul>
<li><a class="el" href="group__normgate.html#ga2a3794103125f1e3cfa103f8b1963656" title="Measures a single qubit, collapsing it randomly to 0 or 1.">measure()</a></li>
<li><a class="el" href="group__normgate.html#ga34457f7f62ccd75fb7d3fe67cd2f815a" title="Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...">collapseToOutcome()</a></li>
<li><a class="el" href="group__debug.html#gae53fad7ebafccf236ad62b41e3244214" title="Seeds the random number generator with the (master node) current time and process ID.">seedQuESTDefault()</a></li>
<li><a class="el" href="group__debug.html#ga555451c697ea4a9d27389155f68fdabc" title="Seeds the random number generator with a custom array of key(s), overriding the default keys.">seedQuEST()</a></li>
</ul>
</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">qureg</td><td>object representing the set of all qubits </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">measureQubit</td><td>qubit to measure </td></tr>
    <tr><td class="paramdir">[out]</td><td class="paramname">outcomeProb</td><td>a pointer to a qreal which is set to the probability of the occurred outcome </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the measurement outcome, 0 or 1 </dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname"><a class="el" href="group__debug.html#ga51a64b05d31ef9bcf6a63ce26c0092db" title="An internal function called when invalid arguments are passed to a QuEST API call,...">invalidQuESTInputError()</a></td><td><ul>
<li>if <code>measureQubit</code> is outside [0, <code>qureg.numQubitsRepresented</code>) </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section author"><dt>Author</dt><dd>Ania Brown (state-vector) </dd>
<dd>
Tyson Jones (density matrix) </dd></dl>

<p class="definition">Definition at line <a class="el" href="QuEST_8c_source.html#l00985">985</a> of file <a class="el" href="QuEST_8c_source.html">QuEST.c</a>.</p>
<div class="fragment"><div class="line"><a name="l00985"></a><span class="lineno">  985</span>&#160;                                                                        {</div>
<div class="line"><a name="l00986"></a><span class="lineno">  986</span>&#160;    <a class="code" href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a>(qureg, measureQubit, __func__);</div>
<div class="line"><a name="l00987"></a><span class="lineno">  987</span>&#160; </div>
<div class="line"><a name="l00988"></a><span class="lineno">  988</span>&#160;    <span class="keywordtype">int</span> outcome;</div>
<div class="line"><a name="l00989"></a><span class="lineno">  989</span>&#160;    <span class="keywordflow">if</span> (qureg.<a class="code" href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">isDensityMatrix</a>)</div>
<div class="line"><a name="l00990"></a><span class="lineno">  990</span>&#160;        outcome = <a class="code" href="QuEST__common_8c.html#ae4ebc1f4dd48922bfb30ad1692310269">densmatr_measureWithStats</a>(qureg, measureQubit, outcomeProb);</div>
<div class="line"><a name="l00991"></a><span class="lineno">  991</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00992"></a><span class="lineno">  992</span>&#160;        outcome = <a class="code" href="QuEST__common_8c.html#ac2eb81c71d0e0fbec7be5b45b1db1448">statevec_measureWithStats</a>(qureg, measureQubit, outcomeProb);</div>
<div class="line"><a name="l00993"></a><span class="lineno">  993</span>&#160;    </div>
<div class="line"><a name="l00994"></a><span class="lineno">  994</span>&#160;    <a class="code" href="QuEST__qasm_8c.html#a0befde437a58ef8fe38495bfc2a16f0e">qasm_recordMeasurement</a>(qureg, measureQubit);</div>
<div class="line"><a name="l00995"></a><span class="lineno">  995</span>&#160;    <span class="keywordflow">return</span> outcome;</div>
<div class="line"><a name="l00996"></a><span class="lineno">  996</span>&#160;}</div>
</div><!-- fragment -->
<p class="reference">References <a class="el" href="QuEST__common_8c_source.html#l00372">densmatr_measureWithStats()</a>, <a class="el" href="QuEST_8h_source.html#l00325">Qureg::isDensityMatrix</a>, <a class="el" href="QuEST__qasm_8c_source.html#l00411">qasm_recordMeasurement()</a>, <a class="el" href="QuEST__common_8c_source.html#l00364">statevec_measureWithStats()</a>, and <a class="el" href="QuEST__validation_8c_source.html#l00400">validateTarget()</a>.</p>

<p class="reference">Referenced by <a class="el" href="test__gates_8cpp_source.html#l00213">TEST_CASE()</a>.</p>

</div>
</div>
</div><!-- contents -->
<div class="ttc" id="aQuEST__validation_8c_html_a8accabb8a9d573c2ff80305841c3053d"><div class="ttname"><a href="QuEST__validation_8c.html#a8accabb8a9d573c2ff80305841c3053d">validateMeasurementProb</a></div><div class="ttdeci">void validateMeasurementProb(qreal prob, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00527">QuEST_validation.c:527</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_ac31c45c5a31c523be0eb26abba6cf598"><div class="ttname"><a href="QuEST__validation_8c.html#ac31c45c5a31c523be0eb26abba6cf598">validateTarget</a></div><div class="ttdeci">void validateTarget(Qureg qureg, int targetQubit, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00400">QuEST_validation.c:400</a></div></div>
<div class="ttc" id="aQuEST__validation_8c_html_ad613c75ff252a88e54f911053bd2032c"><div class="ttname"><a href="QuEST__validation_8c.html#ad613c75ff252a88e54f911053bd2032c">validateOutcome</a></div><div class="ttdeci">void validateOutcome(int outcome, const char *caller)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__validation_8c_source.html#l00523">QuEST_validation.c:523</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a63cb88a5f4eb12fef087435b8db3f8eb"><div class="ttname"><a href="QuEST__internal_8h.html#a63cb88a5f4eb12fef087435b8db3f8eb">statevec_calcProbOfOutcome</a></div><div class="ttdeci">qreal statevec_calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01312">QuEST_cpu_distributed.c:1312</a></div></div>
<div class="ttc" id="agroup__type_html_ga7740e349b4f8bae6451547680f0ce2d6"><div class="ttname"><a href="group__type.html#ga7740e349b4f8bae6451547680f0ce2d6">qreal</a></div><div class="ttdeci">#define qreal</div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a5658f2ecbbd4ea425db5f7dc7fc4ba92"><div class="ttname"><a href="QuEST__internal_8h.html#a5658f2ecbbd4ea425db5f7dc7fc4ba92">densmatr_collapseToKnownProbOutcome</a></div><div class="ttdeci">void densmatr_collapseToKnownProbOutcome(Qureg qureg, int measureQubit, int outcome, qreal outcomeProb)</div><div class="ttdoc">Renorms (/prob) every | * outcome * &gt;&lt; * outcome * | state, setting all others to zero.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu_8c_source.html#l00791">QuEST_cpu.c:791</a></div></div>
<div class="ttc" id="aQuEST__qasm_8c_html_a0befde437a58ef8fe38495bfc2a16f0e"><div class="ttname"><a href="QuEST__qasm_8c.html#a0befde437a58ef8fe38495bfc2a16f0e">qasm_recordMeasurement</a></div><div class="ttdeci">void qasm_recordMeasurement(Qureg qureg, int measureQubit)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__qasm_8c_source.html#l00411">QuEST_qasm.c:411</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_a008becc4a18f868340836e0ab9fd6df6"><div class="ttname"><a href="QuEST__internal_8h.html#a008becc4a18f868340836e0ab9fd6df6">statevec_collapseToKnownProbOutcome</a></div><div class="ttdeci">void statevec_collapseToKnownProbOutcome(Qureg qureg, int measureQubit, int outcome, qreal outcomeProb)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01368">QuEST_cpu_distributed.c:1368</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_ac2eb81c71d0e0fbec7be5b45b1db1448"><div class="ttname"><a href="QuEST__common_8c.html#ac2eb81c71d0e0fbec7be5b45b1db1448">statevec_measureWithStats</a></div><div class="ttdeci">int statevec_measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00364">QuEST_common.c:364</a></div></div>
<div class="ttc" id="astructQureg_html_acf78445e9435d09f44f0cc832c6aee79"><div class="ttname"><a href="structQureg.html#acf78445e9435d09f44f0cc832c6aee79">Qureg::isDensityMatrix</a></div><div class="ttdeci">int isDensityMatrix</div><div class="ttdoc">Whether this instance is a density-state representation.</div><div class="ttdef"><b>Definition:</b> <a href="QuEST_8h_source.html#l00325">QuEST.h:325</a></div></div>
<div class="ttc" id="aQuEST__internal_8h_html_ae37b3eff5d3affbc1edfe216cabc1c53"><div class="ttname"><a href="QuEST__internal_8h.html#ae37b3eff5d3affbc1edfe216cabc1c53">densmatr_calcProbOfOutcome</a></div><div class="ttdeci">qreal densmatr_calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__cpu__distributed_8c_source.html#l01328">QuEST_cpu_distributed.c:1328</a></div></div>
<div class="ttc" id="aQuEST__common_8c_html_ae4ebc1f4dd48922bfb30ad1692310269"><div class="ttname"><a href="QuEST__common_8c.html#ae4ebc1f4dd48922bfb30ad1692310269">densmatr_measureWithStats</a></div><div class="ttdeci">int densmatr_measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb)</div><div class="ttdef"><b>Definition:</b> <a href="QuEST__common_8c_source.html#l00372">QuEST_common.c:372</a></div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
</body>
        <script type="text/javascript" src="boot.js"></script>
</html>