blob: 3b9ddae05af4d314e129c4de78d090a4f0a1f97a [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SystemDSContext &mdash; SystemDS 2.0.0 documentation</title>
<link rel="stylesheet" href="../../static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../static/documentation_options.js"></script>
<script src="../../static/jquery.js"></script>
<script src="../../static/underscore.js"></script>
<script src="../../static/doctools.js"></script>
<script src="../../static/language_data.js"></script>
<script type="text/javascript" src="../../static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Matrix" href="../matrix/matrix.html" />
<link rel="prev" title="Algorithms" href="../operator/algorithms.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home" alt="Documentation Home"> SystemDS
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Getting Started:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started/install.html">Install SystemDS</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started/simple_examples.html">QuickStart</a></li>
</ul>
<p class="caption"><span class="caption-text">Guides</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../guide/federated.html">Federated Environment</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/algorithms_basics.html">Built-in Algorithms</a></li>
</ul>
<p class="caption"><span class="caption-text">API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../operator/algorithms.html">Algorithms</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">SystemDSContext</a></li>
<li class="toctree-l1"><a class="reference internal" href="../matrix/matrix.html">Matrix</a></li>
<li class="toctree-l1"><a class="reference internal" href="../matrix/federated.html">Federated</a></li>
<li class="toctree-l1"><a class="reference internal" href="../operator/operation_node.html">Operation Node</a></li>
</ul>
<p class="caption"><span class="caption-text">Internals API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../script_building/dag.html">Dag</a></li>
<li class="toctree-l1"><a class="reference internal" href="../script_building/script.html">Script</a></li>
<li class="toctree-l1"><a class="reference internal" href="../utils/converters.html">Converters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../utils/helpers.html">Helpers</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">SystemDS</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
<li>SystemDSContext</li>
<li class="wy-breadcrumbs-aside">
<a href="../../sources/api/context/systemds_context.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="systemdscontext">
<h1>SystemDSContext<a class="headerlink" href="#systemdscontext" title="Permalink to this headline"></a></h1>
<p>All operations using SystemDS need a java instance running.
The connection is ensured by an <code class="docutils literal notranslate"><span class="pre">SystemDSContext</span></code> object.
An <code class="docutils literal notranslate"><span class="pre">SystemDSContext</span></code> object can be created using:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">systemds.context</span> <span class="kn">import</span> <span class="n">SystemDSContext</span>
<span class="n">sds</span> <span class="o">=</span> <span class="n">SystemDSContext</span><span class="p">()</span>
</pre></div>
</div>
<p>When the calculations are finished the context has to be closed again:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sds</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<p>Since it is annoying that it is always necessary to close the context, <code class="docutils literal notranslate"><span class="pre">SystemDSContext</span></code>
implements the python context management protocol, which supports the following syntax:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">SystemDSContext</span><span class="p">()</span> <span class="k">as</span> <span class="n">sds</span><span class="p">:</span>
<span class="c1"># do something with sds which is an SystemDSContext</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>This will automatically close the <code class="docutils literal notranslate"><span class="pre">SystemDSContext</span></code> once the with-block is left.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Creating a context is an expensive procedure, because a sub-process starting a JVM might have to start, therefore
try to do this only once for your program, or always leave at least one context open.</p>
</div>
<dl class="py class">
<dt id="systemds.context.SystemDSContext">
<em class="property">class </em><code class="sig-prename descclassname">systemds.context.</code><code class="sig-name descname">SystemDSContext</code><a class="headerlink" href="#systemds.context.SystemDSContext" title="Permalink to this definition"></a></dt>
<dd><p>A context with a connection to a java instance with which SystemDS operations are executed.
The java process is started and is running using a random tcp port for instruction parsing.</p>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#systemds.context.SystemDSContext.__init__" title="Permalink to this definition"></a></dt>
<dd><p>Starts a new instance of SystemDSContext, in which the connection to a JVM systemds instance is handled
Any new instance of this SystemDS Context, would start a separate new JVM.</p>
<p>Standard out and standard error form the JVM is also handled in this class, filling up Queues,
that can be read from to get the printed statements from the JVM.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.close">
<code class="sig-name descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#systemds.context.SystemDSContext.close" title="Permalink to this definition"></a></dt>
<dd><p>Close the connection to the java process and do necessary cleanup.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.exception_and_close">
<code class="sig-name descname">exception_and_close</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">e</span></em><span class="sig-paren">)</span><a class="headerlink" href="#systemds.context.SystemDSContext.exception_and_close" title="Permalink to this definition"></a></dt>
<dd><p>Method for printing exception, printing stdout and error, while also closing the context correctly.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.full">
<code class="sig-name descname">full</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">shape</span><span class="p">:</span> <span class="n">Tuple<span class="p">[</span>int<span class="p">, </span>int<span class="p">]</span></span></em>, <em class="sig-param"><span class="n">value</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.context.SystemDSContext.full" title="Permalink to this definition"></a></dt>
<dd><p>Generates a matrix completely filled with a value</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>sds_context</strong> – SystemDS context</p></li>
<li><p><strong>shape</strong> – shape (rows and cols) of the matrix TODO tensor</p></li>
<li><p><strong>value</strong> – the value to fill all cells with</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the OperationNode representing this operation</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.get_stderr">
<code class="sig-name descname">get_stderr</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">lines</span><span class="p">:</span> <span class="n">int</span> <span class="o">=</span> <span class="default_value">- 1</span></em><span class="sig-paren">)</span><a class="headerlink" href="#systemds.context.SystemDSContext.get_stderr" title="Permalink to this definition"></a></dt>
<dd><p>Getter for the stderr of the java subprocess
The output is taken from the stderr queue and returned in a new list.
:param lines: The number of lines to try to read from the stderr queue.
default -1 prints all current lines in the queue.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.get_stdout">
<code class="sig-name descname">get_stdout</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">lines</span><span class="p">:</span> <span class="n">int</span> <span class="o">=</span> <span class="default_value">- 1</span></em><span class="sig-paren">)</span><a class="headerlink" href="#systemds.context.SystemDSContext.get_stdout" title="Permalink to this definition"></a></dt>
<dd><p>Getter for the stdout of the java subprocess
The output is taken from the stdout queue and returned in a new list.
:param lines: The number of lines to try to read from the stdout queue.
default -1 prints all current lines in the queue.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.rand">
<code class="sig-name descname">rand</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">rows</span><span class="p">:</span> <span class="n">int</span></em>, <em class="sig-param"><span class="n">cols</span><span class="p">:</span> <span class="n">int</span></em>, <em class="sig-param"><span class="n">min</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">max</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pdf</span><span class="p">:</span> <span class="n">str</span> <span class="o">=</span> <span class="default_value">'uniform'</span></em>, <em class="sig-param"><span class="n">sparsity</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">seed</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">lambd</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">1</span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.context.SystemDSContext.rand" title="Permalink to this definition"></a></dt>
<dd><p>Generates a matrix filled with random values</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>sds_context</strong> – SystemDS context</p></li>
<li><p><strong>rows</strong> – number of rows</p></li>
<li><p><strong>cols</strong> – number of cols</p></li>
<li><p><strong>min</strong> – min value for cells</p></li>
<li><p><strong>max</strong> – max value for cells</p></li>
<li><p><strong>pdf</strong> – “uniform”/”normal”/”poison” distribution</p></li>
<li><p><strong>sparsity</strong> – fraction of non-zero cells</p></li>
<li><p><strong>seed</strong> – random seed</p></li>
<li><p><strong>lambd</strong> – lamda value for “poison” distribution</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.read">
<code class="sig-name descname">read</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">path</span><span class="p">:</span> <span class="n">os.PathLike</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; OperationNode<a class="headerlink" href="#systemds.context.SystemDSContext.read" title="Permalink to this definition"></a></dt>
<dd><p>Read an file from disk. Supportted types include:
CSV, Matrix Market(coordinate), Text(i,j,v), SystemDS Binay
See: <a class="reference external" href="http://apache.github.io/systemds/site/dml-language-reference#readwrite-built-in-functions">http://apache.github.io/systemds/site/dml-language-reference#readwrite-built-in-functions</a> for more details
:return: an Operation Node, containing the read data.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.scalar">
<code class="sig-name descname">scalar</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">v</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; OperationNode<a class="headerlink" href="#systemds.context.SystemDSContext.scalar" title="Permalink to this definition"></a></dt>
<dd><p>Construct an scalar value, this can contain str, float, double, integers and booleans.
:return: An <cite>OperationNode</cite> containing the scalar value.</p>
</dd></dl>
<dl class="py method">
<dt id="systemds.context.SystemDSContext.seq">
<code class="sig-name descname">seq</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">start</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span></em>, <em class="sig-param"><span class="n">stop</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">step</span><span class="p">:</span> <span class="n">Union<span class="p">[</span>float<span class="p">, </span>int<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">1</span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.context.SystemDSContext.seq" title="Permalink to this definition"></a></dt>
<dd><p>Create a single column vector with values from <cite>start</cite> to <cite>stop</cite> and an increment of <cite>step</cite>.
If no stop is defined and only one parameter is given, then start will be 0 and the parameter will be interpreted as
stop.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>sds_context</strong> – SystemDS context</p></li>
<li><p><strong>start</strong> – the starting value</p></li>
<li><p><strong>stop</strong> – the maximum value</p></li>
<li><p><strong>step</strong> – the step size</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>the OperationNode representing this operation</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../matrix/matrix.html" class="btn btn-neutral float-right" title="Matrix" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../operator/algorithms.html" class="btn btn-neutral float-left" title="Algorithms" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2020, Apache SystemDS
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>