Skip to content

Commit

Permalink
deploy: fd4ffc0
Browse files Browse the repository at this point in the history
  • Loading branch information
korgan00 committed Nov 7, 2024
1 parent db37a6a commit cf69ec2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 57 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: bfb74b9364f4ee537e9ab0833f71f68a
config: 82eb5cbae7d979a34df362b19b0feaec
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified .doctrees/environment.pickle
Binary file not shown.
Binary file modified .doctrees/stubs/qiskit_serverless.core.LocalClient.doctree
Binary file not shown.
59 changes: 19 additions & 40 deletions _modules/qiskit_serverless/core/clients/local_client.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ <h1>Source code for qiskit_serverless.core.clients.local_client</h1><div class="
<span class="n">Configuration</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">qiskit_serverless.core.function</span> <span class="kn">import</span> <span class="n">QiskitFunction</span><span class="p">,</span> <span class="n">RunnableQiskitFunction</span>
<span class="kn">from</span> <span class="nn">qiskit_serverless.core.local_functions_store</span> <span class="kn">import</span> <span class="n">LocalFunctionsStore</span>
<span class="kn">from</span> <span class="nn">qiskit_serverless.exception</span> <span class="kn">import</span> <span class="n">QiskitServerlessException</span>
<span class="kn">from</span> <span class="nn">qiskit_serverless.serializers.program_serializers</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">QiskitObjectsEncoder</span><span class="p">,</span>
Expand All @@ -378,7 +379,7 @@ <h1>Source code for qiskit_serverless.core.clients.local_client</h1><div class="
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="s2">&quot;local-client&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">in_test</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s2">&quot;IN_TEST&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_jobs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_patterns</span> <span class="o">=</span> <span class="p">[]</span></div>
<span class="bp">self</span><span class="o">.</span><span class="n">_functions</span> <span class="o">=</span> <span class="n">LocalFunctionsStore</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dictionary</span><span class="p">:</span> <span class="nb">dict</span><span class="p">):</span>
Expand All @@ -401,33 +402,30 @@ <h1>Source code for qiskit_serverless.core.clients.local_client</h1><div class="
<span class="n">config</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Configuration</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Job</span><span class="p">:</span>
<span class="c1"># pylint: disable=too-many-locals</span>
<span class="n">title</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">QiskitFunction</span><span class="p">):</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">program</span><span class="o">.</span><span class="n">title</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">title</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">program</span><span class="p">)</span>

<span class="k">for</span> <span class="n">pattern</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_patterns</span><span class="p">:</span>
<span class="k">if</span> <span class="n">pattern</span><span class="p">[</span><span class="s2">&quot;title&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">title</span><span class="p">:</span>
<span class="n">saved_program</span> <span class="o">=</span> <span class="n">pattern</span>
<span class="k">if</span> <span class="n">saved_program</span><span class="p">[</span> <span class="c1"># pylint: disable=possibly-used-before-assignment</span>
<span class="s2">&quot;dependencies&quot;</span>
<span class="p">]:</span>
<span class="n">dept</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">saved_program</span><span class="p">[</span><span class="s2">&quot;dependencies&quot;</span><span class="p">])</span>
<span class="k">for</span> <span class="n">dependency</span> <span class="ow">in</span> <span class="n">dept</span><span class="p">:</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">program</span><span class="o">.</span><span class="n">title</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">program</span><span class="p">,</span> <span class="n">QiskitFunction</span><span class="p">)</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">program</span><span class="p">)</span>

<span class="n">saved_program</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">function</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="n">saved_program</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">QiskitServerlessException</span><span class="p">(</span>
<span class="s2">&quot;QiskitFunction provided is not uploaded to the client. Use upload() first.&quot;</span>
<span class="p">)</span>

<span class="k">if</span> <span class="n">saved_program</span><span class="o">.</span><span class="n">dependencies</span><span class="p">:</span>
<span class="k">for</span> <span class="n">dependency</span> <span class="ow">in</span> <span class="n">saved_program</span><span class="o">.</span><span class="n">dependencies</span><span class="p">:</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">(</span>
<span class="p">[</span><span class="n">sys</span><span class="o">.</span><span class="n">executable</span><span class="p">,</span> <span class="s2">&quot;-m&quot;</span><span class="p">,</span> <span class="s2">&quot;pip&quot;</span><span class="p">,</span> <span class="s2">&quot;install&quot;</span><span class="p">,</span> <span class="n">dependency</span><span class="p">]</span>
<span class="p">)</span>
<span class="n">arguments</span> <span class="o">=</span> <span class="n">arguments</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">env_vars</span> <span class="o">=</span> <span class="p">{</span>
<span class="o">**</span><span class="p">(</span><span class="n">saved_program</span><span class="p">[</span><span class="s2">&quot;env_vars&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="p">{}),</span>
<span class="o">**</span><span class="p">{</span><span class="n">OT_PROGRAM_NAME</span><span class="p">:</span> <span class="n">saved_program</span><span class="p">[</span><span class="s2">&quot;title&quot;</span><span class="p">]},</span>
<span class="o">**</span><span class="p">(</span><span class="n">saved_program</span><span class="o">.</span><span class="n">env_vars</span> <span class="ow">or</span> <span class="p">{}),</span>
<span class="o">**</span><span class="p">{</span><span class="n">OT_PROGRAM_NAME</span><span class="p">:</span> <span class="n">saved_program</span><span class="o">.</span><span class="n">title</span><span class="p">},</span>
<span class="o">**</span><span class="p">{</span><span class="s2">&quot;PATH&quot;</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;PATH&quot;</span><span class="p">]},</span>
<span class="o">**</span><span class="p">{</span><span class="n">ENV_JOB_ARGUMENTS</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">arguments</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">QiskitObjectsEncoder</span><span class="p">)},</span>
<span class="p">}</span>

<span class="k">with</span> <span class="n">Popen</span><span class="p">(</span>
<span class="p">[</span><span class="s2">&quot;python&quot;</span><span class="p">,</span> <span class="n">saved_program</span><span class="p">[</span><span class="s2">&quot;working_dir&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">saved_program</span><span class="p">[</span><span class="s2">&quot;entrypoint&quot;</span><span class="p">]],</span>
<span class="p">[</span><span class="s2">&quot;python&quot;</span><span class="p">,</span> <span class="n">saved_program</span><span class="o">.</span><span class="n">working_dir</span> <span class="o">+</span> <span class="n">saved_program</span><span class="o">.</span><span class="n">entrypoint</span><span class="p">],</span>
<span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
<span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
<span class="n">universal_newlines</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
Expand Down Expand Up @@ -474,34 +472,15 @@ <h1>Source code for qiskit_serverless.core.clients.local_client</h1><div class="

<span class="k">def</span> <span class="nf">upload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">program</span><span class="p">:</span> <span class="n">QiskitFunction</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="n">RunnableQiskitFunction</span><span class="p">]:</span>
<span class="c1"># check if entrypoint exists</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">program</span><span class="o">.</span><span class="n">working_dir</span><span class="p">,</span> <span class="n">program</span><span class="o">.</span><span class="n">entrypoint</span><span class="p">)):</span>
<span class="k">raise</span> <span class="n">QiskitServerlessException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Entrypoint file [</span><span class="si">{</span><span class="n">program</span><span class="o">.</span><span class="n">entrypoint</span><span class="si">}</span><span class="s2">] does not exist &quot;</span>
<span class="sa">f</span><span class="s2">&quot;in [</span><span class="si">{</span><span class="n">program</span><span class="o">.</span><span class="n">working_dir</span><span class="si">}</span><span class="s2">] working directory.&quot;</span>
<span class="p">)</span>

<span class="n">pattern</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">program</span><span class="o">.</span><span class="n">title</span><span class="p">,</span>
<span class="s2">&quot;provider&quot;</span><span class="p">:</span> <span class="n">program</span><span class="o">.</span><span class="n">provider</span><span class="p">,</span>
<span class="s2">&quot;entrypoint&quot;</span><span class="p">:</span> <span class="n">program</span><span class="o">.</span><span class="n">entrypoint</span><span class="p">,</span>
<span class="s2">&quot;working_dir&quot;</span><span class="p">:</span> <span class="n">program</span><span class="o">.</span><span class="n">working_dir</span><span class="p">,</span>
<span class="s2">&quot;env_vars&quot;</span><span class="p">:</span> <span class="n">program</span><span class="o">.</span><span class="n">env_vars</span><span class="p">,</span>
<span class="s2">&quot;arguments&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({}),</span>
<span class="s2">&quot;dependencies&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">program</span><span class="o">.</span><span class="n">dependencies</span> <span class="ow">or</span> <span class="p">[]),</span>
<span class="s2">&quot;client&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="p">,</span>
<span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_patterns</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pattern</span><span class="p">)</span>
<span class="k">return</span> <span class="n">RunnableQiskitFunction</span><span class="o">.</span><span class="n">from_json</span><span class="p">(</span><span class="n">pattern</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_functions</span><span class="o">.</span><span class="n">upload</span><span class="p">(</span><span class="n">program</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">functions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">RunnableQiskitFunction</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns list of programs.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="n">RunnableQiskitFunction</span><span class="o">.</span><span class="n">from_json</span><span class="p">(</span><span class="n">program</span><span class="p">)</span> <span class="k">for</span> <span class="n">program</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_patterns</span><span class="p">]</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_functions</span><span class="o">.</span><span class="n">functions</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">function</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">provider</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="n">RunnableQiskitFunction</span><span class="p">]:</span>
<span class="n">functions</span> <span class="o">=</span> <span class="p">{</span><span class="n">function</span><span class="o">.</span><span class="n">title</span><span class="p">:</span> <span class="n">function</span> <span class="k">for</span> <span class="n">function</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">functions</span><span class="p">()}</span>
<span class="k">return</span> <span class="n">functions</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">title</span><span class="p">)</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_functions</span><span class="o">.</span><span class="n">function</span><span class="p">(</span><span class="n">title</span><span class="p">)</span></div>
</pre></div>
</article>
</div>
Expand Down
Loading

0 comments on commit cf69ec2

Please sign in to comment.