User Interface Plugins

class pygal_panel.PygalAssembler

An assembler for pygal panel contents.

Variables:_chart – The pygal chart object to put into a panel

Cell Plugins

Custom Cell

Provides prototype cell from which all other cells should derive.

Tip

For writing your own cells, those that are run in a separate process will not emit any print statements. Cells that are threadsafe and set to always reprocess will run in the main process and will thus print to your console. Running a circuit with debug turned on will force all cells to run in a single thread and therefore all cells will be able to print to the console in this mode.

To run your circuit in debug, you can type the following in your console:

>>> run(debug=True, step=1)

You can increase the step size to run multiple cells.

class custom_cell.Custom

This is the abstract type that all PyCells should derive from. It provides the default class variables as well as some convenience functions that all cells will need. All derivative cells should return the process function defined here. The Custom class also provides a unique py_id to each cell that derives from it.

Parameters:
  • inputs (dict) – A dictionary of input sockets. Derivative classes can override this variable to supply thier own input sockets.
  • outputs (dict) – A dictionary of output sockets. Derivative classes can override to supply thier own output sockets.
  • inflows (list) – A list of input sockets that may only accept a Quantum ReturnCode. Return codes are an enum defined by Quantum API.
  • outflows (dict) – A dictionary of output sockets that may only hold a ReturnCode.
  • required (list) – A list of required sockets by name.
  • threadsafe (boolean) – Determines if a cell will run in a separate thread or separate process. If threadsafe, PyCell will attempt to run the cell in a thread, otherwise, it will spawn a separate process just to run the cell.
  • always_reprocess (boolean) – Determines if a cell should always re-process on a subsequent call even if none of the inputs have changed. Default, False.
process(code=None)

Manages the return value that gets passed back to the C++ scheduler. Always call this function at the end of your process implementation and return its value. Your process function should never need to return a value to the scheduler. This function will manage that for you.

Parameters:code (QuReturnCode) – You can pass a return code here which will get passed on to the scheduler.
class custom_cell.ValidInputs(*args, **kwargs)

This is a special dict that assumes all values are QuCellSocket. QuCellSockets can contain validation functions that determine what happens when a client tries to store a value in the socket. ValidInputs helps to manage a dict of these sockets and prevents the QuCellSocket from being overwritten by a primitive type. This preserves any validation functions that may have been registered with the sockets.

Examples:

inputs = ValidInputs(my_socket=QuCellSocket(1.234))
inputs = ValidInputs(a=QuCellSocket('a_value'), b=QuCellSocket('b_value'))
inputs = ValidInputs({'c':QuCellSocket(5)})
inputs = ValidInputs(num=1, char='a')
custom_cell.exception_raiser(func)

Use this decorator on functions that need to raise exceptions and display them in Quantum’s console.

Dataframe

Provides Pandas DataFrame functions.

class dataframe_cell.Column

Create a new DataFrame or Series by specifying a subset of column names.

Parameters:
  • columns (string or list) – Required. A single column name or a list of column names. If a single column is specified, the result will be a Pandas Series. Otherwise, the result will be another DataFrame.
  • data (DataFrame) – Required. The original DataFrame.
Returns:

A subset of columns from the original data.

Return type:

H5

Tip

If columns is a list, the result will be a dataframe. If it is a single string, the result will be a series.

class dataframe_cell.Day

Extract the day from a datetime Series.

Parameters:series (Series) – Required. A Series containing dates.
Returns:A Series containing only the days from the input dates.
Return type:H5
class dataframe_cell.DayOfWeek

Extract the day of week from a datetime Series.

Parameters:series (Series) – Required. A Series containing dates.
Returns:A Series containing only the days of week from the input dates.
Return type:H5
class dataframe_cell.GroupBy

Group a dataframe by specific columns. Columns can be calculated on the fly and supplied to groupby as a list element.

Parameters:
  • dataframe (DataFrame) – Required. The dataframe used for the grouping operation.
  • columns (string) – Required. The name(s) of columns to group by. This can also be an expression operating on a Series. For multiple columns a list is required.
  • aggregation (string) – The method used to summarize groups.
Returns:

Grouped data.

Return type:

H5

class dataframe_cell.H5(file, node='/', df=None, **kwargs)

Proxy object for hdf5 storage. Used as a lightweight communication object between dataframe cell sockets.

Parameters:node (string) – A group label.
columns

Provides a column index iterable.

data_columns

Provides an iterable of columns that are indexed as data.

df

The dataframe.

node = None

The node that this H5 object represents.

select(*args, **kwargs)

Executes a select operation on the hdf5 object.

select_column(*args, **kwargs)

Grabs a series from the store.

store

Warning

This is not thread-safe. Do not attempt to access from multiple threads without a locking mechanism.

class dataframe_cell.Head

Creates a new dataframe from the first few rows of the input DataFrame.

Parameters:
  • rows (int) – Number of rows to return.
  • data (H5) – Required. The source data.
Returns:

The requested number rows.

Return type:

H5

class dataframe_cell.Iloc

Create a dataframe subset using the iloc function.

Parameters:
  • axis0 (int, list of int, slice) – Rows to return by position
  • axis1 (int, list of int, slice) – Columns to return by position
  • data (H5) – Required. The source data.
Returns:

The requested rows and columns.

Return type:

H5

class dataframe_cell.IsNull

Checks for NaN elements in a Series

Parameters:series (Series) – Required. The data to check.
Returns:A Series indicating where elements of the input are NaN.
Return type:H5
class dataframe_cell.Loc

Create a dataframe subset using the loc function.

Parameters:
  • axis0 (label, list of labels) – Rows to return by label
  • axis1 (label, list of labels) – Columns to return by label
  • data (H5) – Required. The source data.
Returns:

The requested rows and columns.

Return type:

H5

class dataframe_cell.Merge

Merge DataFrame objects by performing a database-style join operation by columns or indexes.

If joining columns on columns, the DataFrame indexes will be ignored. Otherwise if joining indexes on indexes or indexes on a column or columns, the index will be passed on.

Parameters:
  • A (DataFrame) – The left operand of a merge.
  • B (DataFrame) – The right operand of a merge.
  • how ('left', 'right', 'outer', 'inner', default 'inner') –

    The method to use for merging.

    • left: use only keys from left frame (SQL: left outer join)
    • right: use only keys from right frame (SQL: right outer join)
    • outer: use union of keys from both frames (SQL: full outer join)
    • inner: use intersection of keys from both frames (SQL: inner join)
  • on (label or list) – Field names to join on. Must be found in both DataFrames. If on is None and not merging on indexes, then it merges on the intersection of the columns by default.
  • left_on (label or list, or array-like) – Field names to join on in left DataFrame. Can be a vector or list of vectors of the length of the DataFrame to use a particular vector as the join key instead of columns.
  • right_on (label or list, or array-like) – Field names to join on in right DataFrame or vector/list of vectors per left_on docs.
  • left_index (boolean, default False) – Use the index from the left DataFrame as the join key(s). If it is a MultiIndex, the number of keys in the other DataFrame (either the index or a number of columns) must match the number of levels.
  • right_index (boolean, default False) – Use the index from the right DataFrame as the join key. Same caveats as left_index.
  • sort (boolean, default False) – Sort the join keys lexicographically in the result DataFrame.
  • suffixes (2-length sequence (tuple, list, ..)) – Suffix to apply to overlapping column names in the left and right side, respectively.
  • copy (boolean, default True) – If False, do not copy data unnecessarily
Returns:

The merged result.

Return type:

H5

class dataframe_cell.Month

Extract the month from a datetime Series.

Parameters:series (Series) – Required. A Series containing dates.
Returns:A Series containing only the months from the input dates.
Return type:H5
class dataframe_cell.NotNull

Checks for non-NaN elements in a Series

Parameters:series (Series) – Required. The data to check.
Returns:A Series indicating where elements of the input are not NaN.
Return type:H5
class dataframe_cell.Pivot

Reshape data (produce a “pivot” table) based on column values. Uses unique values from index / columns to form axes and return either DataFrame or Panel, depending on whether you request a single value column (DataFrame) or all columns (Panel).

Parameters:
  • dataframe (DataFrame) – Required. The data to pivot.
  • index (string or object) – Column name to use to make new frame’s index. If None, uses existing index.
  • columns (string or object) – Required. Column name to use to make new frame’s columns.
  • values (string or object) – Column name to use for populating new frame’s values.

Tip

The pivot operation is a special case of a sequence of more primitive operations– set_index, sort_index, unstack in that order. Finer control can be achieved by using the generalized operations.

class dataframe_cell.Read_CSV

Converts a csv file to a DataFrame.

Parameters:
  • csv (str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)) – Required. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is expected. For instance, a local file could be file ://localhost/path/to/table.csv
  • index_col (int or sequence or False, default None) – Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider index_col=False to force pandas to _not_ use the first column as the index (row names)
  • parse_dates (boolean or list of ints or names or list of lists or dict, default False) –

    Determines if dates should be auto-parsed.

    • boolean. If True -> try parsing the index.
    • list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column.
    • list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column.
    • dict, e.g. {‘foo’ : [1, 3]} -> parse columns 1, 3 as date and call result ‘foo’
  • infer_datetime_format (boolean, default False) – If True and parse_dates is enabled for a column, attempt to infer the datetime format to speed up the processing.
  • data_columns (list) – Columns to index
  • min_itemsize (dict) – Specification of minimum field sizes. The parameter should be a dict of fieldnames for keys and integers for their respective sizes. ex: {‘A’:10, ‘B’:100}
Returns:

The parsed csv file.

Return type:

H5

class dataframe_cell.Select

Create a new DataFrame from an existing one based on a boolean Series.

Parameters:
  • data (DataFrame) – Required. The source data.
  • sieve (Series) – Required. A boolean Series used as a filter.
  • expression (string) – Conditions used for the where clause of a query.
Returns:

A subset of data.

Return type:

H5

class dataframe_cell.Set_Index

Assign indexes to a dataframe to speed up data retrievals.

Parameters:
  • dataframe (DataFrame) – Required. The data to re-index.
  • columns (String) – Required. A single column name or a list of column names.
Returns:

Re-indexed data.

Return type:

H5

class dataframe_cell.Sort_Index

Sorts a Series by its index.

Parameters:series (Series) – Required. The data to sort.
Returns:The sorted data.
Return type:H5
class dataframe_cell.Sort_Values

Sorts a dataframe using a list of columns, or sorts a series using its values column.

Parameters:
  • data (DataFrame or Series) – Required. Data to sort.
  • column_list (list or None) – Order by these columns. If the data is a Series, then this parameter should be None.
Returns:

The sorted data

Return type:

H5

class dataframe_cell.Stack

Pivot a level of the (possibly hierarchical) column labels, returning a DataFrame (or Series in the case of an object with a single level of column labels) having a hierarchical index with a new inner-most level of row labels. The level involved will automatically get sorted.

Parameters:
  • data (DataFrame or Series) – Required. The data to unstack.
  • level (int, string, or list of these, default -1 (last level)) – Level(s) of index to stack, can pass level name
  • dropna (boolean, default True) – Whether to drop rows in the resulting Frame/Series with no valid values
Returns:

Unstacked data.

Return type:

H5

class dataframe_cell.Str_Contains

Determines if a substring can be matched to each string of a Series.

Parameters:
  • series (Series) – Required. The series of string data.
  • substring (string) – The string to match.
Returns:

A new Series indicating if a match was successful.

Return type:

H5

class dataframe_cell.Str_Len

Determines the length of each string in a Series.

Parameters:series (Series) – Required. The series of string data.
Returns:A new Series with calculated lengths of strings.
Return type:H5
class dataframe_cell.Str_StartsWith

Determines if a substring can be matched to the beginning of each string of a Series.

Parameters:
  • series (Series) – Required. The series of string data.
  • substring (string) – The string to match.
Returns:

A new Series indicating if a match was successful.

Return type:

H5

class dataframe_cell.Tail

Creates a new dataframe from the last few rows of the input DataFrame.

Parameters:
  • rows (int) – Number of rows to return.
  • data (DataFrame) – Required. The source data.
Returns:

The requested number rows.

Return type:

H5

class dataframe_cell.Unstack

Pivot a level of the (necessarily hierarchical) index labels, returning a DataFrame having a new level of column labels whose inner-most level consists of the pivoted index labels. If the index is not a MultiIndex, the output will be a Series (the analogue of stack when the columns are not a MultiIndex). The level involved will automatically get sorted.

Parameters:
  • data (DataFrame or Series) – Required. The data to unstack.
  • level (int, string, or list of these, default -1 (last level)) – Level(s) of index to unstack, can pass level name
  • fill_value (any) – replace NaN with this value if the unstack produces missing values.
Returns:

Unstacked data.

Return type:

H5

class dataframe_cell.Update

Updates values of a specific column inside of a DataFrame. If a column doesn’t exist, it will be automatically created.

Parameters:
  • dataframe (DataFrame) – Required. The dataframe that recieves the updates.
  • column (string) – Required. The dataframe column that recieves the updates.
  • rows (Series) – A series of True and False that determines which rows get updates.
  • values (Series) – Required. The values to write into the dataframe. The row index should correspond to the row index of the dataframe.
Returns:

The updated data.

Return type:

H5

class dataframe_cell.Value_Counts

Count by index of a Series.

Parameters:series (Series) – Required. The data to tally.
Returns:The tallied data.
Return type:H5
class dataframe_cell.Year

Extract the year from a datetime Series.

Parameters:series (Series) – Required. A Series containing dates.
Returns:A Series containing only the years from the input dates.
Return type:H5
dataframe_cell.data_process(func)

Decorator for cell processes that execute a dataframe operation. It creates a new node in the data store that holds the return value for the wrapped generator. This result is then wrapped back up into an H5 and returned, where it is expected to be put into an output socket for the next cell to use.

Note

This decorator runs the decorated function in a separate processor and therefore, will not emit any print statements.

dataframe_cell.operator_process(op)

Documentation coming soon.

Logic

Logic cells are graph nodes that determine the branching structure of process execution.

class logic_cell.Bitwise_And

Bitwise and operator.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a&b.

class logic_cell.Bitwise_Or

Bitwise or operator.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a|b.

class logic_cell.Eq

Tests for equality.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a==b.

class logic_cell.Gt

Greater than.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a>b.

class logic_cell.Gte

Greater than or equal.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a>=b.

class logic_cell.If

A switch element that determines which cell will be executed next.

Inputs

>>:Execution pin. Receives an execution token from upstream connection.
Condition:A boolean value that determines which output pin recieves the next execution token.

Outputs

True >>:Connects to the cell to execute if true.
False >>:Connects to the cell to execute if false.
class logic_cell.Lt

Less than.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a<b.

class logic_cell.Lte

Less than or equal.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

Whether or not a<=b.

Projection

The projection module produces tensors that are intended to represent your model’s time series results.

class projection_cell.AstColumn

AstColumn produces a vector tranformation using t as the input vector and f(t) as the transformation function. The function f should be an expression in terms of t, and the t socket should contain a list.

Example:

>>> a = AstColumn()
>>> a.inputs['f(t)'] = 't**2'
>>> a.inputs['t'] = [1, 2, 3, 4]
>>> a.process()
0
>>> a.outputs['ans']
[1, 4, 9, 16]
class projection_cell.NumpyColumn

NumpyColumn produces a vector tranformation using t as the input vector and f(t) as the transformation function. The function f should be an expression in terms of t, and the t socket should contain a list.

Example:

>>> a = NumpyColumn()
>>> a.inputs['f(t)'] = 't**2'
>>> a.inputs['t'] = [1, 2, 3, 4]
>>> a.process()
0
>>> a.outputs['ans']
array([1, 4, 9, 16])

Pylang

The pylang plugin provides common python functions.

class pylang_cell.Add

Adds two objects.

Parameters:
  • aRequired. Left operand.
  • bRequired. Right operand.
Returns:

The result of a+b.

class pylang_cell.Div

Divides two objects.

Parameters:
  • aRequired. Left operand.
  • bRequired. Right operand.
Returns:

The result of a/b.

class pylang_cell.Int_Div

Integer divides two objects. Equivalent to the // operator.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

The result of a//b.

class pylang_cell.Len

Calls len() on an iterable object.

Parameters:obj (any) – Required. An iterable object.
Returns:The length of the object.
Return type:int
class pylang_cell.Mul

Multiplies two objects.

Parameters:
  • aRequired. Left operand.
  • bRequired. Right operand.
Returns:

The result of a*b.

class pylang_cell.Pow

Exponentiates a base by a power. Equivalent to the ** operator.

Parameters:
  • a – Left operand.
  • b – Right operand.
Returns:

The result of a**b.

class pylang_cell.Sub

Adds two objects.

Parameters:
  • aRequired. Left operand.
  • bRequired. Right operand.
Returns:

The result of a-b.

class pylang_cell.To_List

Wraps an object into a list with the object as the single element in the list.

Parameters:obj (any) – Required. The object to be put into the empty list.
Returns:A list with a single element.
Return type:list
class pylang_cell.Variable

Declares a Python variable.

Parameters:value (any) – Required. The value held by the variable.
class symengine_cell.Exp

The constant e

class symengine_cell.Expand

Expands the input formula

class symengine_cell.Exponentiate

Exponentiate base by exp

class symengine_cell.Sympify

Converts back and forth ))<>(( between Symengine and Sympy

Sympy

Provides symbolic math capabilities.

class sympy_cell.CDF

Converts a symbolic distribution into a callable cumulative distribution.

class sympy_cell.Calculate

Converts a QuSym into a function and calculates the value given supplied input variables.

class sympy_cell.Exp

Exponentiate \(e^x\)

Parameters:x (QuSym) – The exponent.
Returns:The symbolic result of exponentiating with base e.
Return type:QuSym
class sympy_cell.Expand

Expands the input formula

class sympy_cell.Ln

Natural log \(ln(x)\)

Parameters:x (QuSym) – The number to log
Returns:The symbolic result of ln(x).
Return type:QuSym
class sympy_cell.Normal

Creates a symbolic normal distribution.

Parameters:
  • name (String) – Symbolic name of the distribution.
  • mean (numeric) – Mean of the normal distribution
  • variance (numeric) – Variance of the normal distribution
class sympy_cell.QuSym(expression, variables=None, values=None)

An object that combines symbolic representation with numeric evaluation.

class sympy_cell.Sqrt

Square root \(\sqrt{x}\)

Parameters:x (QuSym) – The square root radicand
Returns:The symbolic result of \(\sqrt{x}\).
Return type:QuSym
class sympy_cell.Subs

Searches for a subexpression in \(f(x)\) and substitutes it with the expression in replacement.

Parameters:
  • f(x) (QuSym) – The expression to search
  • subexpr (QuSym) – The subexpression to match
  • replacement (QuSym) – The expression to use as substitute
class sympy_cell.SymFunction

Creates an abstract function.

Parameters:name (str) – The symbol’s name. This is what gets printed in latex output.
class sympy_cell.Symbol

Creates a symbol.

Parameters:
  • name (String) – The symbol’s name. This is what gets printed in latex output.
  • value (numeric) – The input value that will be used for computation.
sympy_cell.eval_sym(out_key=None, in_key=None, eval_key='eval', eval_out='result')

A decorator for processes that allow calculation of a numeric result. The output socket located at out_key must be a QuSym. Optionally, an in_key may be supplied if the formula is found in an input. The formula must be supplied in at least one of the two. If both are supplied, the output formula will have priority.

Parameters:
  • out_key (str) – The key to the output socket containing a QuSym that includes all values neccessary for evaluation.
  • in_key (str) – The key to the input socket containing a QuSym that includes all values neccessary for evaluation.
  • eval_key (str or bool) – The input key containing a boolean which determines if a numeric result should be calculated. Optionally, you can supply a boolean directly.
  • eval_out (str) – The output key where the numeric result is written