Skip to content

Commit

Permalink
Deploying to gh-pages from @ d9286dc 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
OkuyanBoga committed Nov 18, 2024
1 parent 21106f3 commit f142f0d
Show file tree
Hide file tree
Showing 36 changed files with 1,288 additions and 1,338 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 60296e6230937c468ef0123b6e9abd35
config: fd0f18b2c959210f7255f890be098f25
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified _images/tutorials_08_quantum_kernel_trainer_14_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/tutorials_08_quantum_kernel_trainer_4_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/tutorials_10_effective_dimension_33_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _images/tutorials_10_effective_dimension_41_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 24 additions & 21 deletions _modules/qiskit_machine_learning/neural_networks/estimator_qnn.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span>

<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">copy</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Sequence</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
Expand All @@ -419,6 +418,7 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="kn">from</span> <span class="nn">qiskit.primitives</span> <span class="kn">import</span> <span class="n">BaseEstimator</span><span class="p">,</span> <span class="n">BaseEstimatorV1</span><span class="p">,</span> <span class="n">Estimator</span><span class="p">,</span> <span class="n">EstimatorResult</span>
<span class="kn">from</span> <span class="nn">qiskit.quantum_info</span> <span class="kn">import</span> <span class="n">SparsePauliOp</span>
<span class="kn">from</span> <span class="nn">qiskit.quantum_info.operators.base_operator</span> <span class="kn">import</span> <span class="n">BaseOperator</span>
<span class="kn">from</span> <span class="nn">qiskit.transpiler.passmanager</span> <span class="kn">import</span> <span class="n">BasePassManager</span>


<span class="kn">from</span> <span class="nn">..gradients</span> <span class="kn">import</span> <span class="p">(</span>
Expand Down Expand Up @@ -511,8 +511,8 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="n">weight_params</span><span class="p">:</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">Parameter</span><span class="p">]</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">gradient</span><span class="p">:</span> <span class="n">BaseEstimatorGradient</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">input_gradients</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
<span class="n">num_virtual_qubits</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">default_precision</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.015625</span><span class="p">,</span>
<span class="n">pass_manager</span><span class="p">:</span> <span class="n">BasePassManager</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="w"> </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Args:</span>
Expand Down Expand Up @@ -543,11 +543,12 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="sd"> Note that this parameter is ``False`` by default, and must be explicitly set to</span>
<span class="sd"> ``True`` for a proper gradient computation when using</span>
<span class="sd"> :class:`~qiskit_machine_learning.connectors.TorchConnector`.</span>
<span class="sd"> num_virtual_qubits: Number of virtual qubits.</span>
<span class="sd"> default_precision: The default precision for the estimator if not specified during run.</span>

<span class="sd"> pass_manager: The pass manager to transpile the circuits, if necessary.</span>
<span class="sd"> Defaults to ``None``, as some primitives do not need transpiled circuits.</span>
<span class="sd"> Raises:</span>
<span class="sd"> QiskitMachineLearningError: Invalid parameter values.</span>
<span class="sd"> QiskitMachineLearningError: Gradient is required if</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">estimator</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">estimator</span> <span class="o">=</span> <span class="n">Estimator</span><span class="p">()</span>
Expand All @@ -560,19 +561,17 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="n">period</span><span class="o">=</span><span class="s2">&quot;4 months&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">estimator</span> <span class="o">=</span> <span class="n">estimator</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_org_circuit</span> <span class="o">=</span> <span class="n">circuit</span>

<span class="k">if</span> <span class="n">num_virtual_qubits</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span> <span class="o">=</span> <span class="n">circuit</span><span class="o">.</span><span class="n">num_qubits</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;No number of qubits was not specified (</span><span class="si">{</span><span class="n">num_virtual_qubits</span><span class="si">}</span><span class="s2">) and was retrieved from &quot;</span>
<span class="o">+</span> <span class="sa">f</span><span class="s2">&quot;`circuit` (</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span><span class="si">:</span><span class="s2">d</span><span class="si">}</span><span class="s2">). If `circuit` is transpiled, this may cause &quot;</span>
<span class="o">+</span> <span class="s2">&quot;unstable behaviour.&quot;</span><span class="p">,</span>
<span class="ne">UserWarning</span><span class="p">,</span>
<span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">circuit</span><span class="o">.</span><span class="n">layout</span><span class="p">,</span> <span class="s2">&quot;_input_qubit_count&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span> <span class="o">=</span> <span class="n">circuit</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">_input_qubit_count</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span> <span class="o">=</span> <span class="n">num_virtual_qubits</span>
<span class="k">if</span> <span class="n">pass_manager</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span> <span class="o">=</span> <span class="n">circuit</span><span class="o">.</span><span class="n">num_qubits</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">circuit</span> <span class="o">=</span> <span class="n">pass_manager</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">circuit</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">num_virtual_qubits</span> <span class="o">=</span> <span class="n">circuit</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">_input_qubit_count</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_org_circuit</span> <span class="o">=</span> <span class="n">circuit</span>

<span class="k">if</span> <span class="n">observables</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">observables</span> <span class="o">=</span> <span class="n">SparsePauliOp</span><span class="o">.</span><span class="n">from_sparse_list</span><span class="p">(</span>
Expand All @@ -592,14 +591,18 @@ <h1>Source code for qiskit_machine_learning.neural_networks.estimator_qnn</h1><d
<span class="bp">self</span><span class="o">.</span><span class="n">_input_params</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">input_params</span><span class="p">)</span> <span class="k">if</span> <span class="n">input_params</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_weight_params</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">weight_params</span><span class="p">)</span> <span class="k">if</span> <span class="n">weight_params</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">[]</span>

<span class="c1"># set gradient</span>
<span class="k">if</span> <span class="n">gradient</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">estimator</span><span class="p">,</span> <span class="n">BaseEstimatorV2</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">QiskitMachineLearningError</span><span class="p">(</span>
<span class="s2">&quot;Please provide a gradient with pass manager initialised.&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">estimator</span><span class="p">,</span> <span class="n">BaseEstimatorV1</span><span class="p">):</span>
<span class="n">gradient</span> <span class="o">=</span> <span class="n">ParamShiftEstimatorGradient</span><span class="p">(</span><span class="n">estimator</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">estimator</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span>
<span class="s2">&quot;No gradient function provided, creating a gradient function.&quot;</span>
<span class="s2">&quot; If your Estimator requires transpilation, please provide a pass manager.&quot;</span>
<span class="p">)</span>
<span class="n">gradient</span> <span class="o">=</span> <span class="n">ParamShiftEstimatorGradient</span><span class="p">(</span>
<span class="n">estimator</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">estimator</span><span class="p">,</span> <span class="n">pass_manager</span><span class="o">=</span><span class="n">pass_manager</span>
<span class="p">)</span>

<span class="n">gradient</span> <span class="o">=</span> <span class="n">ParamShiftEstimatorGradient</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">estimator</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_default_precision</span> <span class="o">=</span> <span class="n">default_precision</span>
<span class="bp">self</span><span class="o">.</span><span class="n">gradient</span> <span class="o">=</span> <span class="n">gradient</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_input_gradients</span> <span class="o">=</span> <span class="n">input_gradients</span>
Expand Down
Loading

0 comments on commit f142f0d

Please sign in to comment.