repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
mabuchilab/QNET
src/qnet/algebra/core/indexed_operations.py
IndexedSum.terms
def terms(self): """Iterator over the terms of the sum Yield from the (possibly) infinite list of terms of the indexed sum, if the sum was written out explicitly. Each yielded term in an instance of :class:`.Expression` """ from qnet.algebra.core.scalar_algebra import Sc...
python
def terms(self): """Iterator over the terms of the sum Yield from the (possibly) infinite list of terms of the indexed sum, if the sum was written out explicitly. Each yielded term in an instance of :class:`.Expression` """ from qnet.algebra.core.scalar_algebra import Sc...
[ "def", "terms", "(", "self", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "scalar_algebra", "import", "ScalarValue", "for", "mapping", "in", "yield_from_ranges", "(", "self", ".", "ranges", ")", ":", "term", "=", "self", ".", "term", ".", ...
Iterator over the terms of the sum Yield from the (possibly) infinite list of terms of the indexed sum, if the sum was written out explicitly. Each yielded term in an instance of :class:`.Expression`
[ "Iterator", "over", "the", "terms", "of", "the", "sum" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/indexed_operations.py#L75-L88
train
62,800
mabuchilab/QNET
src/qnet/algebra/core/indexed_operations.py
IndexedSum.doit
def doit( self, classes=None, recursive=True, indices=None, max_terms=None, **kwargs): """Write out the indexed sum explicitly If `classes` is None or :class:`IndexedSum` is in `classes`, (partially) write out the indexed sum in to an explicit sum of terms. If `r...
python
def doit( self, classes=None, recursive=True, indices=None, max_terms=None, **kwargs): """Write out the indexed sum explicitly If `classes` is None or :class:`IndexedSum` is in `classes`, (partially) write out the indexed sum in to an explicit sum of terms. If `r...
[ "def", "doit", "(", "self", ",", "classes", "=", "None", ",", "recursive", "=", "True", ",", "indices", "=", "None", ",", "max_terms", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "super", "(", ")", ".", "doit", "(", "classes", ",", ...
Write out the indexed sum explicitly If `classes` is None or :class:`IndexedSum` is in `classes`, (partially) write out the indexed sum in to an explicit sum of terms. If `recursive` is True, write out each of the new sum's summands by calling its :meth:`doit` method. Args: ...
[ "Write", "out", "the", "indexed", "sum", "explicitly" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/indexed_operations.py#L100-L124
train
62,801
mabuchilab/QNET
src/qnet/algebra/core/indexed_operations.py
IndexedSum.make_disjunct_indices
def make_disjunct_indices(self, *others): """Return a copy with modified indices to ensure disjunct indices with `others`. Each element in `others` may be an index symbol (:class:`.IdxSym`), a index-range object (:class:`.IndexRangeBase`) or list of index-range objects, or an in...
python
def make_disjunct_indices(self, *others): """Return a copy with modified indices to ensure disjunct indices with `others`. Each element in `others` may be an index symbol (:class:`.IdxSym`), a index-range object (:class:`.IndexRangeBase`) or list of index-range objects, or an in...
[ "def", "make_disjunct_indices", "(", "self", ",", "*", "others", ")", ":", "new", "=", "self", "other_index_symbols", "=", "set", "(", ")", "for", "other", "in", "others", ":", "try", ":", "if", "isinstance", "(", "other", ",", "IdxSym", ")", ":", "oth...
Return a copy with modified indices to ensure disjunct indices with `others`. Each element in `others` may be an index symbol (:class:`.IdxSym`), a index-range object (:class:`.IndexRangeBase`) or list of index-range objects, or an indexed operation (something with a ``ranges`` attribut...
[ "Return", "a", "copy", "with", "modified", "indices", "to", "ensure", "disjunct", "indices", "with", "others", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/indexed_operations.py#L194-L234
train
62,802
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_field_js_assets
def codemirror_field_js_assets(*args): """ Tag to render CodeMirror Javascript assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_js_assets form.myfield1 form.myfield2 %} """ manifesto = CodemirrorAssetTagRender() manife...
python
def codemirror_field_js_assets(*args): """ Tag to render CodeMirror Javascript assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_js_assets form.myfield1 form.myfield2 %} """ manifesto = CodemirrorAssetTagRender() manife...
[ "def", "codemirror_field_js_assets", "(", "*", "args", ")", ":", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "manifesto", ".", "register_from_fields", "(", "*", "args", ")", "return", "mark_safe", "(", "manifesto", ".", "js_html", "(", ")", ")" ]
Tag to render CodeMirror Javascript assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_js_assets form.myfield1 form.myfield2 %}
[ "Tag", "to", "render", "CodeMirror", "Javascript", "assets", "needed", "for", "all", "given", "fields", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L152-L165
train
62,803
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_field_css_assets
def codemirror_field_css_assets(*args): """ Tag to render CodeMirror CSS assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_css_assets form.myfield1 form.myfield2 %} """ manifesto = CodemirrorAssetTagRender() manifesto.r...
python
def codemirror_field_css_assets(*args): """ Tag to render CodeMirror CSS assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_css_assets form.myfield1 form.myfield2 %} """ manifesto = CodemirrorAssetTagRender() manifesto.r...
[ "def", "codemirror_field_css_assets", "(", "*", "args", ")", ":", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "manifesto", ".", "register_from_fields", "(", "*", "args", ")", "return", "mark_safe", "(", "manifesto", ".", "css_html", "(", ")", ")" ]
Tag to render CodeMirror CSS assets needed for all given fields. Example: :: {% load djangocodemirror_tags %} {% codemirror_field_css_assets form.myfield1 form.myfield2 %}
[ "Tag", "to", "render", "CodeMirror", "CSS", "assets", "needed", "for", "all", "given", "fields", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L169-L182
train
62,804
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_field_js_bundle
def codemirror_field_js_bundle(field): """ Filter to get CodeMirror Javascript bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_js_bundle }} Arguments: field (django.forms.fields.Field): A form field t...
python
def codemirror_field_js_bundle(field): """ Filter to get CodeMirror Javascript bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_js_bundle }} Arguments: field (django.forms.fields.Field): A form field t...
[ "def", "codemirror_field_js_bundle", "(", "field", ")", ":", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "manifesto", ".", "register_from_fields", "(", "field", ")", "try", ":", "bundle_name", "=", "manifesto", ".", "js_bundle_names", "(", ")", "[", ...
Filter to get CodeMirror Javascript bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_js_bundle }} Arguments: field (django.forms.fields.Field): A form field that contains a widget :class:`djangocod...
[ "Filter", "to", "get", "CodeMirror", "Javascript", "bundle", "name", "needed", "for", "a", "single", "field", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L186-L217
train
62,805
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_field_css_bundle
def codemirror_field_css_bundle(field): """ Filter to get CodeMirror CSS bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_css_bundle }} Arguments: field (djangocodemirror.fields.CodeMirrorField): A for...
python
def codemirror_field_css_bundle(field): """ Filter to get CodeMirror CSS bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_css_bundle }} Arguments: field (djangocodemirror.fields.CodeMirrorField): A for...
[ "def", "codemirror_field_css_bundle", "(", "field", ")", ":", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "manifesto", ".", "register_from_fields", "(", "field", ")", "try", ":", "bundle_name", "=", "manifesto", ".", "css_bundle_names", "(", ")", "[", ...
Filter to get CodeMirror CSS bundle name needed for a single field. Example: :: {% load djangocodemirror_tags %} {{ form.myfield|codemirror_field_css_bundle }} Arguments: field (djangocodemirror.fields.CodeMirrorField): A form field. Raises: CodeMirrorFieldBundleE...
[ "Filter", "to", "get", "CodeMirror", "CSS", "bundle", "name", "needed", "for", "a", "single", "field", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L221-L251
train
62,806
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_parameters
def codemirror_parameters(field): """ Filter to include CodeMirror parameters as a JSON string for a single field. This must be called only on an allready rendered field, meaning you must not use this filter on a field before a form. Else, the field widget won't be correctly initialized. E...
python
def codemirror_parameters(field): """ Filter to include CodeMirror parameters as a JSON string for a single field. This must be called only on an allready rendered field, meaning you must not use this filter on a field before a form. Else, the field widget won't be correctly initialized. E...
[ "def", "codemirror_parameters", "(", "field", ")", ":", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "names", "=", "manifesto", ".", "register_from_fields", "(", "field", ")", "config", "=", "manifesto", ".", "get_codemirror_parameters", "(", "names", "...
Filter to include CodeMirror parameters as a JSON string for a single field. This must be called only on an allready rendered field, meaning you must not use this filter on a field before a form. Else, the field widget won't be correctly initialized. Example: :: {% load django...
[ "Filter", "to", "include", "CodeMirror", "parameters", "as", "a", "JSON", "string", "for", "a", "single", "field", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L255-L281
train
62,807
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
codemirror_instance
def codemirror_instance(config_name, varname, element_id, assets=True): """ Return HTML to init a CodeMirror instance for an element. This will output the whole HTML needed to initialize a CodeMirror instance with needed assets loading. Assets can be omitted with the ``assets`` option. Example...
python
def codemirror_instance(config_name, varname, element_id, assets=True): """ Return HTML to init a CodeMirror instance for an element. This will output the whole HTML needed to initialize a CodeMirror instance with needed assets loading. Assets can be omitted with the ``assets`` option. Example...
[ "def", "codemirror_instance", "(", "config_name", ",", "varname", ",", "element_id", ",", "assets", "=", "True", ")", ":", "output", "=", "io", ".", "StringIO", "(", ")", "manifesto", "=", "CodemirrorAssetTagRender", "(", ")", "manifesto", ".", "register", "...
Return HTML to init a CodeMirror instance for an element. This will output the whole HTML needed to initialize a CodeMirror instance with needed assets loading. Assets can be omitted with the ``assets`` option. Example: :: {% load djangocodemirror_tags %} {% codemirror...
[ "Return", "HTML", "to", "init", "a", "CodeMirror", "instance", "for", "an", "element", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L285-L328
train
62,808
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
CodemirrorAssetTagRender.resolve_widget
def resolve_widget(self, field): """ Given a Field or BoundField, return widget instance. Todo: Raise an exception if given field object does not have a widget. Arguments: field (Field or BoundField): A field instance. Returns: d...
python
def resolve_widget(self, field): """ Given a Field or BoundField, return widget instance. Todo: Raise an exception if given field object does not have a widget. Arguments: field (Field or BoundField): A field instance. Returns: d...
[ "def", "resolve_widget", "(", "self", ",", "field", ")", ":", "# When filter is used within template we have to reach the field", "# instance through the BoundField.", "if", "hasattr", "(", "field", ",", "'field'", ")", ":", "widget", "=", "field", ".", "field", ".", ...
Given a Field or BoundField, return widget instance. Todo: Raise an exception if given field object does not have a widget. Arguments: field (Field or BoundField): A field instance. Returns: django.forms.widgets.Widget: Retrieved widget from giv...
[ "Given", "a", "Field", "or", "BoundField", "return", "widget", "instance", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L26-L48
train
62,809
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
CodemirrorAssetTagRender.register_from_fields
def register_from_fields(self, *args): """ Register config name from field widgets Arguments: *args: Fields that contains widget :class:`djangocodemirror.widget.CodeMirrorWidget`. Returns: list: List of registered config names from fields. ...
python
def register_from_fields(self, *args): """ Register config name from field widgets Arguments: *args: Fields that contains widget :class:`djangocodemirror.widget.CodeMirrorWidget`. Returns: list: List of registered config names from fields. ...
[ "def", "register_from_fields", "(", "self", ",", "*", "args", ")", ":", "names", "=", "[", "]", "for", "field", "in", "args", ":", "widget", "=", "self", ".", "resolve_widget", "(", "field", ")", "self", ".", "register", "(", "widget", ".", "config_nam...
Register config name from field widgets Arguments: *args: Fields that contains widget :class:`djangocodemirror.widget.CodeMirrorWidget`. Returns: list: List of registered config names from fields.
[ "Register", "config", "name", "from", "field", "widgets" ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L50-L68
train
62,810
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
CodemirrorAssetTagRender.render_asset_html
def render_asset_html(self, path, tag_template): """ Render HTML tag for a given path. Arguments: path (string): Relative path from static directory. tag_template (string): Template string for HTML tag. Returns: string: HTML tag with url from given p...
python
def render_asset_html(self, path, tag_template): """ Render HTML tag for a given path. Arguments: path (string): Relative path from static directory. tag_template (string): Template string for HTML tag. Returns: string: HTML tag with url from given p...
[ "def", "render_asset_html", "(", "self", ",", "path", ",", "tag_template", ")", ":", "url", "=", "os", ".", "path", ".", "join", "(", "settings", ".", "STATIC_URL", ",", "path", ")", "return", "tag_template", ".", "format", "(", "url", "=", "url", ")" ...
Render HTML tag for a given path. Arguments: path (string): Relative path from static directory. tag_template (string): Template string for HTML tag. Returns: string: HTML tag with url from given path.
[ "Render", "HTML", "tag", "for", "a", "given", "path", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L70-L83
train
62,811
sveetch/djangocodemirror
djangocodemirror/templatetags/djangocodemirror_tags.py
CodemirrorAssetTagRender.codemirror_html
def codemirror_html(self, config_name, varname, element_id): """ Render HTML for a CodeMirror instance. Since a CodeMirror instance have to be attached to a HTML element, this method requires a HTML element identifier with or without the ``#`` prefix, it depends from template in...
python
def codemirror_html(self, config_name, varname, element_id): """ Render HTML for a CodeMirror instance. Since a CodeMirror instance have to be attached to a HTML element, this method requires a HTML element identifier with or without the ``#`` prefix, it depends from template in...
[ "def", "codemirror_html", "(", "self", ",", "config_name", ",", "varname", ",", "element_id", ")", ":", "parameters", "=", "json", ".", "dumps", "(", "self", ".", "get_codemirror_parameters", "(", "config_name", ")", ",", "sort_keys", "=", "True", ")", "retu...
Render HTML for a CodeMirror instance. Since a CodeMirror instance have to be attached to a HTML element, this method requires a HTML element identifier with or without the ``#`` prefix, it depends from template in ``settings.CODEMIRROR_FIELD_INIT_JS`` (default one require to not ...
[ "Render", "HTML", "for", "a", "CodeMirror", "instance", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/templatetags/djangocodemirror_tags.py#L123-L148
train
62,812
mabuchilab/QNET
docs/conf.py
run_apidoc
def run_apidoc(_): """Generage API documentation""" import better_apidoc better_apidoc.main([ 'better-apidoc', '-t', os.path.join('.', '_templates'), '--force', '--no-toc', '--separate', '-o', os.path.join('.', 'API'), os.path.join('..'...
python
def run_apidoc(_): """Generage API documentation""" import better_apidoc better_apidoc.main([ 'better-apidoc', '-t', os.path.join('.', '_templates'), '--force', '--no-toc', '--separate', '-o', os.path.join('.', 'API'), os.path.join('..'...
[ "def", "run_apidoc", "(", "_", ")", ":", "import", "better_apidoc", "better_apidoc", ".", "main", "(", "[", "'better-apidoc'", ",", "'-t'", ",", "os", ".", "path", ".", "join", "(", "'.'", ",", "'_templates'", ")", ",", "'--force'", ",", "'--no-toc'", ",...
Generage API documentation
[ "Generage", "API", "documentation" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/docs/conf.py#L22-L35
train
62,813
mabuchilab/QNET
src/qnet/printing/treeprinting.py
_shorten_render
def _shorten_render(renderer, max_len): """Return a modified that returns the representation of expr, or '...' if that representation is longer than `max_len`""" def short_renderer(expr): res = renderer(expr) if len(res) > max_len: return '...' else: return r...
python
def _shorten_render(renderer, max_len): """Return a modified that returns the representation of expr, or '...' if that representation is longer than `max_len`""" def short_renderer(expr): res = renderer(expr) if len(res) > max_len: return '...' else: return r...
[ "def", "_shorten_render", "(", "renderer", ",", "max_len", ")", ":", "def", "short_renderer", "(", "expr", ")", ":", "res", "=", "renderer", "(", "expr", ")", "if", "len", "(", "res", ")", ">", "max_len", ":", "return", "'...'", "else", ":", "return", ...
Return a modified that returns the representation of expr, or '...' if that representation is longer than `max_len`
[ "Return", "a", "modified", "that", "returns", "the", "representation", "of", "expr", "or", "...", "if", "that", "representation", "is", "longer", "than", "max_len" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/printing/treeprinting.py#L11-L22
train
62,814
mabuchilab/QNET
src/qnet/algebra/__init__.py
init_algebra
def init_algebra(*, default_hs_cls='LocalSpace'): """Initialize the algebra system Args: default_hs_cls (str): The name of the :class:`.LocalSpace` subclass that should be used when implicitly creating Hilbert spaces, e.g. in :class:`.OperatorSymbol` """ from qnet.algeb...
python
def init_algebra(*, default_hs_cls='LocalSpace'): """Initialize the algebra system Args: default_hs_cls (str): The name of the :class:`.LocalSpace` subclass that should be used when implicitly creating Hilbert spaces, e.g. in :class:`.OperatorSymbol` """ from qnet.algeb...
[ "def", "init_algebra", "(", "*", ",", "default_hs_cls", "=", "'LocalSpace'", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "hilbert_space_algebra", "import", "LocalSpace", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra"...
Initialize the algebra system Args: default_hs_cls (str): The name of the :class:`.LocalSpace` subclass that should be used when implicitly creating Hilbert spaces, e.g. in :class:`.OperatorSymbol`
[ "Initialize", "the", "algebra", "system" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/__init__.py#L7-L22
train
62,815
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.register
def register(self, name): """ Register configuration for an editor instance. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``. Raises: UnknowConfigError: If given config name does not exist in ...
python
def register(self, name): """ Register configuration for an editor instance. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``. Raises: UnknowConfigError: If given config name does not exist in ...
[ "def", "register", "(", "self", ",", "name", ")", ":", "if", "name", "not", "in", "settings", ".", "CODEMIRROR_SETTINGS", ":", "msg", "=", "(", "\"Given config name '{}' does not exists in \"", "\"'settings.CODEMIRROR_SETTINGS'.\"", ")", "raise", "UnknowConfigError", ...
Register configuration for an editor instance. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``. Raises: UnknowConfigError: If given config name does not exist in ``settings.CODEMIRROR_SETTINGS``. ...
[ "Register", "configuration", "for", "an", "editor", "instance", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L49-L88
train
62,816
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.register_many
def register_many(self, *args): """ Register many configuration names. Arguments: *args: Config names as strings. Returns: list: List of registered configs. """ params = [] for name in args: params.append(self.register(name)) ...
python
def register_many(self, *args): """ Register many configuration names. Arguments: *args: Config names as strings. Returns: list: List of registered configs. """ params = [] for name in args: params.append(self.register(name)) ...
[ "def", "register_many", "(", "self", ",", "*", "args", ")", ":", "params", "=", "[", "]", "for", "name", "in", "args", ":", "params", ".", "append", "(", "self", ".", "register", "(", "name", ")", ")", "return", "params" ]
Register many configuration names. Arguments: *args: Config names as strings. Returns: list: List of registered configs.
[ "Register", "many", "configuration", "names", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L90-L104
train
62,817
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.resolve_mode
def resolve_mode(self, name): """ From given mode name, return mode file path from ``settings.CODEMIRROR_MODES`` map. Arguments: name (string): Mode name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_MODES``. ...
python
def resolve_mode(self, name): """ From given mode name, return mode file path from ``settings.CODEMIRROR_MODES`` map. Arguments: name (string): Mode name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_MODES``. ...
[ "def", "resolve_mode", "(", "self", ",", "name", ")", ":", "if", "name", "not", "in", "settings", ".", "CODEMIRROR_MODES", ":", "msg", "=", "(", "\"Given config name '{}' does not exists in \"", "\"'settings.CODEMIRROR_MODES'.\"", ")", "raise", "UnknowModeError", "(",...
From given mode name, return mode file path from ``settings.CODEMIRROR_MODES`` map. Arguments: name (string): Mode name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_MODES``. Returns: string: Mode file pa...
[ "From", "given", "mode", "name", "return", "mode", "file", "path", "from", "settings", ".", "CODEMIRROR_MODES", "map", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L114-L134
train
62,818
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.resolve_theme
def resolve_theme(self, name): """ From given theme name, return theme file path from ``settings.CODEMIRROR_THEMES`` map. Arguments: name (string): Theme name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_THEM...
python
def resolve_theme(self, name): """ From given theme name, return theme file path from ``settings.CODEMIRROR_THEMES`` map. Arguments: name (string): Theme name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_THEM...
[ "def", "resolve_theme", "(", "self", ",", "name", ")", ":", "if", "name", "not", "in", "settings", ".", "CODEMIRROR_THEMES", ":", "msg", "=", "(", "\"Given theme name '{}' does not exists in \"", "\"'settings.CODEMIRROR_THEMES'.\"", ")", "raise", "UnknowThemeError", "...
From given theme name, return theme file path from ``settings.CODEMIRROR_THEMES`` map. Arguments: name (string): Theme name. Raises: KeyError: When given name does not exist in ``settings.CODEMIRROR_THEMES``. Returns: string: Theme f...
[ "From", "given", "theme", "name", "return", "theme", "file", "path", "from", "settings", ".", "CODEMIRROR_THEMES", "map", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L136-L156
train
62,819
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.get_configs
def get_configs(self, name=None): """ Returns registred configurations. * If ``name`` argument is not given, default behavior is to return every config from all registred config; * If ``name`` argument is given, just return its config and nothing else; Keywo...
python
def get_configs(self, name=None): """ Returns registred configurations. * If ``name`` argument is not given, default behavior is to return every config from all registred config; * If ``name`` argument is given, just return its config and nothing else; Keywo...
[ "def", "get_configs", "(", "self", ",", "name", "=", "None", ")", ":", "if", "name", ":", "if", "name", "not", "in", "self", ".", "registry", ":", "msg", "=", "\"Given config name '{}' is not registered.\"", "raise", "NotRegisteredError", "(", "msg", ".", "f...
Returns registred configurations. * If ``name`` argument is not given, default behavior is to return every config from all registred config; * If ``name`` argument is given, just return its config and nothing else; Keyword Arguments: name (string): Specific conf...
[ "Returns", "registred", "configurations", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L158-L183
train
62,820
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.get_config
def get_config(self, name): """ Return a registred configuration for given config name. Arguments: name (string): A registred config name. Raises: NotRegisteredError: If given config name does not exist in registry. Returns: dict...
python
def get_config(self, name): """ Return a registred configuration for given config name. Arguments: name (string): A registred config name. Raises: NotRegisteredError: If given config name does not exist in registry. Returns: dict...
[ "def", "get_config", "(", "self", ",", "name", ")", ":", "if", "name", "not", "in", "self", ".", "registry", ":", "msg", "=", "\"Given config name '{}' is not registered.\"", "raise", "NotRegisteredError", "(", "msg", ".", "format", "(", "name", ")", ")", "r...
Return a registred configuration for given config name. Arguments: name (string): A registred config name. Raises: NotRegisteredError: If given config name does not exist in registry. Returns: dict: Configuration.
[ "Return", "a", "registred", "configuration", "for", "given", "config", "name", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L185-L203
train
62,821
sveetch/djangocodemirror
djangocodemirror/manifest.py
CodeMirrorManifest.get_codemirror_parameters
def get_codemirror_parameters(self, name): """ Return CodeMirror parameters for given configuration name. This is a reduced configuration from internal parameters. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``....
python
def get_codemirror_parameters(self, name): """ Return CodeMirror parameters for given configuration name. This is a reduced configuration from internal parameters. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``....
[ "def", "get_codemirror_parameters", "(", "self", ",", "name", ")", ":", "config", "=", "self", ".", "get_config", "(", "name", ")", "return", "{", "k", ":", "config", "[", "k", "]", "for", "k", "in", "config", "if", "k", "not", "in", "self", ".", "...
Return CodeMirror parameters for given configuration name. This is a reduced configuration from internal parameters. Arguments: name (string): Config name from available ones in ``settings.CODEMIRROR_SETTINGS``. Returns: dict: Parameters.
[ "Return", "CodeMirror", "parameters", "for", "given", "configuration", "name", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/manifest.py#L205-L220
train
62,822
mabuchilab/QNET
src/qnet/algebra/core/super_operator_algebra.py
commutator
def commutator(A, B=None): """Commutator of `A` and `B` If ``B != None``, return the commutator :math:`[A,B]`, otherwise return the super-operator :math:`[A,\cdot]`. The super-operator :math:`[A,\cdot]` maps any other operator ``B`` to the commutator :math:`[A, B] = A B - B A`. Args: A: T...
python
def commutator(A, B=None): """Commutator of `A` and `B` If ``B != None``, return the commutator :math:`[A,B]`, otherwise return the super-operator :math:`[A,\cdot]`. The super-operator :math:`[A,\cdot]` maps any other operator ``B`` to the commutator :math:`[A, B] = A B - B A`. Args: A: T...
[ "def", "commutator", "(", "A", ",", "B", "=", "None", ")", ":", "if", "B", ":", "return", "A", "*", "B", "-", "B", "*", "A", "return", "SPre", "(", "A", ")", "-", "SPost", "(", "A", ")" ]
Commutator of `A` and `B` If ``B != None``, return the commutator :math:`[A,B]`, otherwise return the super-operator :math:`[A,\cdot]`. The super-operator :math:`[A,\cdot]` maps any other operator ``B`` to the commutator :math:`[A, B] = A B - B A`. Args: A: The first operator to form the comm...
[ "Commutator", "of", "A", "and", "B" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/super_operator_algebra.py#L331-L348
train
62,823
mabuchilab/QNET
src/qnet/algebra/core/super_operator_algebra.py
liouvillian
def liouvillian(H, Ls=None): r"""Return the Liouvillian super-operator associated with `H` and `Ls` The Liouvillian :math:`\mathcal{L}` generates the Markovian-dynamics of a system via the Master equation: .. math:: \dot{\rho} = \mathcal{L}\rho = -i[H,\rho] + \sum_{j=1}^n \mathcal{...
python
def liouvillian(H, Ls=None): r"""Return the Liouvillian super-operator associated with `H` and `Ls` The Liouvillian :math:`\mathcal{L}` generates the Markovian-dynamics of a system via the Master equation: .. math:: \dot{\rho} = \mathcal{L}\rho = -i[H,\rho] + \sum_{j=1}^n \mathcal{...
[ "def", "liouvillian", "(", "H", ",", "Ls", "=", "None", ")", ":", "if", "Ls", "is", "None", ":", "Ls", "=", "[", "]", "elif", "isinstance", "(", "Ls", ",", "Matrix", ")", ":", "Ls", "=", "Ls", ".", "matrix", ".", "ravel", "(", ")", ".", "toli...
r"""Return the Liouvillian super-operator associated with `H` and `Ls` The Liouvillian :math:`\mathcal{L}` generates the Markovian-dynamics of a system via the Master equation: .. math:: \dot{\rho} = \mathcal{L}\rho = -i[H,\rho] + \sum_{j=1}^n \mathcal{D}[L_j] \rho Args: H...
[ "r", "Return", "the", "Liouvillian", "super", "-", "operator", "associated", "with", "H", "and", "Ls" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/super_operator_algebra.py#L396-L419
train
62,824
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
block_matrix
def block_matrix(A, B, C, D): r"""Generate the operator matrix with quadrants .. math:: \begin{pmatrix} A B \\ C D \end{pmatrix} Args: A (Matrix): Matrix of shape ``(n, m)`` B (Matrix): Matrix of shape ``(n, k)`` C (Matrix): Matrix of shape ``(l, m)`` D (Matrix): Ma...
python
def block_matrix(A, B, C, D): r"""Generate the operator matrix with quadrants .. math:: \begin{pmatrix} A B \\ C D \end{pmatrix} Args: A (Matrix): Matrix of shape ``(n, m)`` B (Matrix): Matrix of shape ``(n, k)`` C (Matrix): Matrix of shape ``(l, m)`` D (Matrix): Ma...
[ "def", "block_matrix", "(", "A", ",", "B", ",", "C", ",", "D", ")", ":", "return", "vstackm", "(", "(", "hstackm", "(", "(", "A", ",", "B", ")", ")", ",", "hstackm", "(", "(", "C", ",", "D", ")", ")", ")", ")" ]
r"""Generate the operator matrix with quadrants .. math:: \begin{pmatrix} A B \\ C D \end{pmatrix} Args: A (Matrix): Matrix of shape ``(n, m)`` B (Matrix): Matrix of shape ``(n, k)`` C (Matrix): Matrix of shape ``(l, m)`` D (Matrix): Matrix of shape ``(l, k)`` Retu...
[ "r", "Generate", "the", "operator", "matrix", "with", "quadrants" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L388-L404
train
62,825
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
permutation_matrix
def permutation_matrix(permutation): r"""Return orthogonal permutation matrix for permutation tuple Return an orthogonal permutation matrix :math:`M_\sigma` for a permutation :math:`\sigma` defined by the image tuple :math:`(\sigma(1), \sigma(2),\dots \sigma(n))`, such that .. math:: ...
python
def permutation_matrix(permutation): r"""Return orthogonal permutation matrix for permutation tuple Return an orthogonal permutation matrix :math:`M_\sigma` for a permutation :math:`\sigma` defined by the image tuple :math:`(\sigma(1), \sigma(2),\dots \sigma(n))`, such that .. math:: ...
[ "def", "permutation_matrix", "(", "permutation", ")", ":", "assert", "check_permutation", "(", "permutation", ")", "n", "=", "len", "(", "permutation", ")", "op_matrix", "=", "np_zeros", "(", "(", "n", ",", "n", ")", ",", "dtype", "=", "int", ")", "for",...
r"""Return orthogonal permutation matrix for permutation tuple Return an orthogonal permutation matrix :math:`M_\sigma` for a permutation :math:`\sigma` defined by the image tuple :math:`(\sigma(1), \sigma(2),\dots \sigma(n))`, such that .. math:: M_\sigma \vec{e}_i = \vec{e}_{\sigma(i)} ...
[ "r", "Return", "orthogonal", "permutation", "matrix", "for", "permutation", "tuple" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L425-L461
train
62,826
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.is_zero
def is_zero(self): """Are all elements of the matrix zero?""" for o in self.matrix.ravel(): try: if not o.is_zero: return False except AttributeError: if not o == 0: return False return True
python
def is_zero(self): """Are all elements of the matrix zero?""" for o in self.matrix.ravel(): try: if not o.is_zero: return False except AttributeError: if not o == 0: return False return True
[ "def", "is_zero", "(", "self", ")", ":", "for", "o", "in", "self", ".", "matrix", ".", "ravel", "(", ")", ":", "try", ":", "if", "not", "o", ".", "is_zero", ":", "return", "False", "except", "AttributeError", ":", "if", "not", "o", "==", "0", ":"...
Are all elements of the matrix zero?
[ "Are", "all", "elements", "of", "the", "matrix", "zero?" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L100-L109
train
62,827
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.conjugate
def conjugate(self): """The element-wise conjugate matrix This is defined only if all the entries in the matrix have a defined conjugate (i.e., they have a `conjugate` method). This is *not* the case for a matrix of operators. In such a case, only an :meth:`elementwise` :func:`a...
python
def conjugate(self): """The element-wise conjugate matrix This is defined only if all the entries in the matrix have a defined conjugate (i.e., they have a `conjugate` method). This is *not* the case for a matrix of operators. In such a case, only an :meth:`elementwise` :func:`a...
[ "def", "conjugate", "(", "self", ")", ":", "try", ":", "return", "Matrix", "(", "np_conjugate", "(", "self", ".", "matrix", ")", ")", "except", "AttributeError", ":", "raise", "NoConjugateMatrix", "(", "\"Matrix %s contains entries that have no defined \"", "\"conju...
The element-wise conjugate matrix This is defined only if all the entries in the matrix have a defined conjugate (i.e., they have a `conjugate` method). This is *not* the case for a matrix of operators. In such a case, only an :meth:`elementwise` :func:`adjoint` would be applicable, but...
[ "The", "element", "-", "wise", "conjugate", "matrix" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L167-L184
train
62,828
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.real
def real(self): """Element-wise real part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the real part Note: A mathematically equivalent way to obtain a real matrix from a complex matrix ``M`` i...
python
def real(self): """Element-wise real part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the real part Note: A mathematically equivalent way to obtain a real matrix from a complex matrix ``M`` i...
[ "def", "real", "(", "self", ")", ":", "def", "re", "(", "val", ")", ":", "if", "hasattr", "(", "val", ",", "'real'", ")", ":", "return", "val", ".", "real", "elif", "hasattr", "(", "val", ",", "'as_real_imag'", ")", ":", "return", "val", ".", "as...
Element-wise real part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the real part Note: A mathematically equivalent way to obtain a real matrix from a complex matrix ``M`` is:: (M.con...
[ "Element", "-", "wise", "real", "part" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L187-L220
train
62,829
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.imag
def imag(self): """Element-wise imaginary part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the imaginary part Note: A mathematically equivalent way to obtain an imaginary matrix from a comple...
python
def imag(self): """Element-wise imaginary part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the imaginary part Note: A mathematically equivalent way to obtain an imaginary matrix from a comple...
[ "def", "imag", "(", "self", ")", ":", "def", "im", "(", "val", ")", ":", "if", "hasattr", "(", "val", ",", "'imag'", ")", ":", "return", "val", ".", "imag", "elif", "hasattr", "(", "val", ",", "'as_real_imag'", ")", ":", "return", "val", ".", "as...
Element-wise imaginary part Raises: NoConjugateMatrix: if entries have no `conjugate` method and no other way to determine the imaginary part Note: A mathematically equivalent way to obtain an imaginary matrix from a complex matrix ``M`` is:: ...
[ "Element", "-", "wise", "imaginary", "part" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L223-L254
train
62,830
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.element_wise
def element_wise(self, func, *args, **kwargs): """Apply a function to each matrix element and return the result in a new operator matrix of the same shape. Args: func (FunctionType): A function to be applied to each element. It must take the element as its first argu...
python
def element_wise(self, func, *args, **kwargs): """Apply a function to each matrix element and return the result in a new operator matrix of the same shape. Args: func (FunctionType): A function to be applied to each element. It must take the element as its first argu...
[ "def", "element_wise", "(", "self", ",", "func", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "s", "=", "self", ".", "shape", "emat", "=", "[", "func", "(", "o", ",", "*", "args", ",", "*", "*", "kwargs", ")", "for", "o", "in", "self"...
Apply a function to each matrix element and return the result in a new operator matrix of the same shape. Args: func (FunctionType): A function to be applied to each element. It must take the element as its first argument. args: Additional positional arguments to...
[ "Apply", "a", "function", "to", "each", "matrix", "element", "and", "return", "the", "result", "in", "a", "new", "operator", "matrix", "of", "the", "same", "shape", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L285-L300
train
62,831
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.series_expand
def series_expand(self, param: Symbol, about, order: int): """Expand the matrix expression as a truncated power series in a scalar parameter. Args: param: Expansion parameter. about (.Scalar): Point about which to expand. order: Maximum order of expansion >= ...
python
def series_expand(self, param: Symbol, about, order: int): """Expand the matrix expression as a truncated power series in a scalar parameter. Args: param: Expansion parameter. about (.Scalar): Point about which to expand. order: Maximum order of expansion >= ...
[ "def", "series_expand", "(", "self", ",", "param", ":", "Symbol", ",", "about", ",", "order", ":", "int", ")", ":", "s", "=", "self", ".", "shape", "emats", "=", "zip", "(", "*", "[", "o", ".", "series_expand", "(", "param", ",", "about", ",", "o...
Expand the matrix expression as a truncated power series in a scalar parameter. Args: param: Expansion parameter. about (.Scalar): Point about which to expand. order: Maximum order of expansion >= 0 Returns: tuple of length (order+1), where the e...
[ "Expand", "the", "matrix", "expression", "as", "a", "truncated", "power", "series", "in", "a", "scalar", "parameter", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L302-L318
train
62,832
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.expand
def expand(self): """Expand each matrix element distributively. Returns: Matrix: Expanded matrix. """ return self.element_wise( lambda o: o.expand() if isinstance(o, QuantumExpression) else o)
python
def expand(self): """Expand each matrix element distributively. Returns: Matrix: Expanded matrix. """ return self.element_wise( lambda o: o.expand() if isinstance(o, QuantumExpression) else o)
[ "def", "expand", "(", "self", ")", ":", "return", "self", ".", "element_wise", "(", "lambda", "o", ":", "o", ".", "expand", "(", ")", "if", "isinstance", "(", "o", ",", "QuantumExpression", ")", "else", "o", ")" ]
Expand each matrix element distributively. Returns: Matrix: Expanded matrix.
[ "Expand", "each", "matrix", "element", "distributively", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L320-L327
train
62,833
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.space
def space(self): """Combined Hilbert space of all matrix elements.""" arg_spaces = [o.space for o in self.matrix.ravel() if hasattr(o, 'space')] if len(arg_spaces) == 0: return TrivialSpace else: return ProductSpace.create(*arg_spaces)
python
def space(self): """Combined Hilbert space of all matrix elements.""" arg_spaces = [o.space for o in self.matrix.ravel() if hasattr(o, 'space')] if len(arg_spaces) == 0: return TrivialSpace else: return ProductSpace.create(*arg_spaces)
[ "def", "space", "(", "self", ")", ":", "arg_spaces", "=", "[", "o", ".", "space", "for", "o", "in", "self", ".", "matrix", ".", "ravel", "(", ")", "if", "hasattr", "(", "o", ",", "'space'", ")", "]", "if", "len", "(", "arg_spaces", ")", "==", "...
Combined Hilbert space of all matrix elements.
[ "Combined", "Hilbert", "space", "of", "all", "matrix", "elements", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L346-L353
train
62,834
mabuchilab/QNET
src/qnet/algebra/core/matrix_algebra.py
Matrix.simplify_scalar
def simplify_scalar(self, func=sympy.simplify): """Simplify all scalar expressions appearing in the Matrix.""" def element_simplify(v): if isinstance(v, sympy.Basic): return func(v) elif isinstance(v, QuantumExpression): return v.simplify_scalar(f...
python
def simplify_scalar(self, func=sympy.simplify): """Simplify all scalar expressions appearing in the Matrix.""" def element_simplify(v): if isinstance(v, sympy.Basic): return func(v) elif isinstance(v, QuantumExpression): return v.simplify_scalar(f...
[ "def", "simplify_scalar", "(", "self", ",", "func", "=", "sympy", ".", "simplify", ")", ":", "def", "element_simplify", "(", "v", ")", ":", "if", "isinstance", "(", "v", ",", "sympy", ".", "Basic", ")", ":", "return", "func", "(", "v", ")", "elif", ...
Simplify all scalar expressions appearing in the Matrix.
[ "Simplify", "all", "scalar", "expressions", "appearing", "in", "the", "Matrix", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/matrix_algebra.py#L355-L366
train
62,835
sveetch/djangocodemirror
sandbox/views.py
ModesSampleFormView.get_initial
def get_initial(self): """ Try to find a demo source for given mode if any, if finded use it to fill the demo textarea. """ initial = {} if self.kwargs.get('mode', None): filename = "{}.txt".format(self.kwargs['mode']) filepath = os.path.join(sett...
python
def get_initial(self): """ Try to find a demo source for given mode if any, if finded use it to fill the demo textarea. """ initial = {} if self.kwargs.get('mode', None): filename = "{}.txt".format(self.kwargs['mode']) filepath = os.path.join(sett...
[ "def", "get_initial", "(", "self", ")", ":", "initial", "=", "{", "}", "if", "self", ".", "kwargs", ".", "get", "(", "'mode'", ",", "None", ")", ":", "filename", "=", "\"{}.txt\"", ".", "format", "(", "self", ".", "kwargs", "[", "'mode'", "]", ")",...
Try to find a demo source for given mode if any, if finded use it to fill the demo textarea.
[ "Try", "to", "find", "a", "demo", "source", "for", "given", "mode", "if", "any", "if", "finded", "use", "it", "to", "fill", "the", "demo", "textarea", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/sandbox/views.py#L33-L47
train
62,836
django-fluent/django-fluent-blogs
fluent_blogs/models/query.py
_get_order_by
def _get_order_by(order, orderby, order_by_fields): """ Return the order by syntax for a model. Checks whether use ascending or descending order, and maps the fieldnames. """ try: # Find the actual database fieldnames for the keyword. db_fieldnames = order_by_fields[orderby] exce...
python
def _get_order_by(order, orderby, order_by_fields): """ Return the order by syntax for a model. Checks whether use ascending or descending order, and maps the fieldnames. """ try: # Find the actual database fieldnames for the keyword. db_fieldnames = order_by_fields[orderby] exce...
[ "def", "_get_order_by", "(", "order", ",", "orderby", ",", "order_by_fields", ")", ":", "try", ":", "# Find the actual database fieldnames for the keyword.", "db_fieldnames", "=", "order_by_fields", "[", "orderby", "]", "except", "KeyError", ":", "raise", "ValueError", ...
Return the order by syntax for a model. Checks whether use ascending or descending order, and maps the fieldnames.
[ "Return", "the", "order", "by", "syntax", "for", "a", "model", ".", "Checks", "whether", "use", "ascending", "or", "descending", "order", "and", "maps", "the", "fieldnames", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L51-L69
train
62,837
django-fluent/django-fluent-blogs
fluent_blogs/models/query.py
query_entries
def query_entries( queryset=None, year=None, month=None, day=None, category=None, category_slug=None, tag=None, tag_slug=None, author=None, author_slug=None, future=False, order=None, orderby=None, limit=None, ): """ Query the entries using a set of predefined filters. Th...
python
def query_entries( queryset=None, year=None, month=None, day=None, category=None, category_slug=None, tag=None, tag_slug=None, author=None, author_slug=None, future=False, order=None, orderby=None, limit=None, ): """ Query the entries using a set of predefined filters. Th...
[ "def", "query_entries", "(", "queryset", "=", "None", ",", "year", "=", "None", ",", "month", "=", "None", ",", "day", "=", "None", ",", "category", "=", "None", ",", "category_slug", "=", "None", ",", "tag", "=", "None", ",", "tag_slug", "=", "None"...
Query the entries using a set of predefined filters. This interface is mainly used by the ``get_entries`` template tag.
[ "Query", "the", "entries", "using", "a", "set", "of", "predefined", "filters", ".", "This", "interface", "is", "mainly", "used", "by", "the", "get_entries", "template", "tag", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L72-L144
train
62,838
django-fluent/django-fluent-blogs
fluent_blogs/models/query.py
query_tags
def query_tags(order=None, orderby=None, limit=None): """ Query the tags, with usage count included. This interface is mainly used by the ``get_tags`` template tag. """ from taggit.models import Tag, TaggedItem # feature is still optional # Get queryset filters for published entries Entr...
python
def query_tags(order=None, orderby=None, limit=None): """ Query the tags, with usage count included. This interface is mainly used by the ``get_tags`` template tag. """ from taggit.models import Tag, TaggedItem # feature is still optional # Get queryset filters for published entries Entr...
[ "def", "query_tags", "(", "order", "=", "None", ",", "orderby", "=", "None", ",", "limit", "=", "None", ")", ":", "from", "taggit", ".", "models", "import", "Tag", ",", "TaggedItem", "# feature is still optional", "# Get queryset filters for published entries", "E...
Query the tags, with usage count included. This interface is mainly used by the ``get_tags`` template tag.
[ "Query", "the", "tags", "with", "usage", "count", "included", ".", "This", "interface", "is", "mainly", "used", "by", "the", "get_tags", "template", "tag", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L147-L184
train
62,839
django-fluent/django-fluent-blogs
fluent_blogs/models/query.py
get_category_for_slug
def get_category_for_slug(slug, language_code=None): """ Find the category for a given slug """ Category = get_category_model() if issubclass(Category, TranslatableModel): return Category.objects.active_translations(language_code, slug=slug).get() else: return Category.objects.ge...
python
def get_category_for_slug(slug, language_code=None): """ Find the category for a given slug """ Category = get_category_model() if issubclass(Category, TranslatableModel): return Category.objects.active_translations(language_code, slug=slug).get() else: return Category.objects.ge...
[ "def", "get_category_for_slug", "(", "slug", ",", "language_code", "=", "None", ")", ":", "Category", "=", "get_category_model", "(", ")", "if", "issubclass", "(", "Category", ",", "TranslatableModel", ")", ":", "return", "Category", ".", "objects", ".", "acti...
Find the category for a given slug
[ "Find", "the", "category", "for", "a", "given", "slug" ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L187-L195
train
62,840
django-fluent/django-fluent-blogs
fluent_blogs/models/query.py
get_date_range
def get_date_range(year=None, month=None, day=None): """ Return a start..end range to query for a specific month, day or year. """ if year is None: return None if month is None: # year only start = datetime(year, 1, 1, 0, 0, 0, tzinfo=utc) end = datetime(year, 12, 31...
python
def get_date_range(year=None, month=None, day=None): """ Return a start..end range to query for a specific month, day or year. """ if year is None: return None if month is None: # year only start = datetime(year, 1, 1, 0, 0, 0, tzinfo=utc) end = datetime(year, 12, 31...
[ "def", "get_date_range", "(", "year", "=", "None", ",", "month", "=", "None", ",", "day", "=", "None", ")", ":", "if", "year", "is", "None", ":", "return", "None", "if", "month", "is", "None", ":", "# year only", "start", "=", "datetime", "(", "year"...
Return a start..end range to query for a specific month, day or year.
[ "Return", "a", "start", "..", "end", "range", "to", "query", "for", "a", "specific", "month", "day", "or", "year", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L198-L220
train
62,841
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
pattern
def pattern(head, *args, mode=1, wc_name=None, conditions=None, **kwargs) \ -> Pattern: """'Flat' constructor for the Pattern class Positional and keyword arguments are mapped into `args` and `kwargs`, respectively. Useful for defining rules that match an instantiated Expression with specific a...
python
def pattern(head, *args, mode=1, wc_name=None, conditions=None, **kwargs) \ -> Pattern: """'Flat' constructor for the Pattern class Positional and keyword arguments are mapped into `args` and `kwargs`, respectively. Useful for defining rules that match an instantiated Expression with specific a...
[ "def", "pattern", "(", "head", ",", "*", "args", ",", "mode", "=", "1", ",", "wc_name", "=", "None", ",", "conditions", "=", "None", ",", "*", "*", "kwargs", ")", "->", "Pattern", ":", "if", "len", "(", "args", ")", "==", "0", ":", "args", "=",...
Flat' constructor for the Pattern class Positional and keyword arguments are mapped into `args` and `kwargs`, respectively. Useful for defining rules that match an instantiated Expression with specific arguments
[ "Flat", "constructor", "for", "the", "Pattern", "class" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L452-L465
train
62,842
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
match_pattern
def match_pattern(expr_or_pattern: object, expr: object) -> MatchDict: """Recursively match `expr` with the given `expr_or_pattern` Args: expr_or_pattern: either a direct expression (equal to `expr` for a successful match), or an instance of :class:`Pattern`. expr: the expression to...
python
def match_pattern(expr_or_pattern: object, expr: object) -> MatchDict: """Recursively match `expr` with the given `expr_or_pattern` Args: expr_or_pattern: either a direct expression (equal to `expr` for a successful match), or an instance of :class:`Pattern`. expr: the expression to...
[ "def", "match_pattern", "(", "expr_or_pattern", ":", "object", ",", "expr", ":", "object", ")", "->", "MatchDict", ":", "try", ":", "# first try expr_or_pattern as a Pattern", "return", "expr_or_pattern", ".", "match", "(", "expr", ")", "except", "AttributeError", ...
Recursively match `expr` with the given `expr_or_pattern` Args: expr_or_pattern: either a direct expression (equal to `expr` for a successful match), or an instance of :class:`Pattern`. expr: the expression to be matched
[ "Recursively", "match", "expr", "with", "the", "given", "expr_or_pattern" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L613-L631
train
62,843
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
MatchDict.update
def update(self, *others): """Update dict with entries from `other` If `other` has an attribute ``success=False`` and ``reason``, those attributes are copied as well """ for other in others: for key, val in other.items(): self[key] = val t...
python
def update(self, *others): """Update dict with entries from `other` If `other` has an attribute ``success=False`` and ``reason``, those attributes are copied as well """ for other in others: for key, val in other.items(): self[key] = val t...
[ "def", "update", "(", "self", ",", "*", "others", ")", ":", "for", "other", "in", "others", ":", "for", "key", ",", "val", "in", "other", ".", "items", "(", ")", ":", "self", "[", "key", "]", "=", "val", "try", ":", "if", "not", "other", ".", ...
Update dict with entries from `other` If `other` has an attribute ``success=False`` and ``reason``, those attributes are copied as well
[ "Update", "dict", "with", "entries", "from", "other" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L83-L97
train
62,844
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
Pattern.extended_arg_patterns
def extended_arg_patterns(self): """Iterator over patterns for positional arguments to be matched This yields the elements of :attr:`args`, extended by their `mode` value """ for arg in self._arg_iterator(self.args): if isinstance(arg, Pattern): if ar...
python
def extended_arg_patterns(self): """Iterator over patterns for positional arguments to be matched This yields the elements of :attr:`args`, extended by their `mode` value """ for arg in self._arg_iterator(self.args): if isinstance(arg, Pattern): if ar...
[ "def", "extended_arg_patterns", "(", "self", ")", ":", "for", "arg", "in", "self", ".", "_arg_iterator", "(", "self", ".", "args", ")", ":", "if", "isinstance", "(", "arg", ",", "Pattern", ")", ":", "if", "arg", ".", "mode", ">", "self", ".", "single...
Iterator over patterns for positional arguments to be matched This yields the elements of :attr:`args`, extended by their `mode` value
[ "Iterator", "over", "patterns", "for", "positional", "arguments", "to", "be", "matched" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L232-L246
train
62,845
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
Pattern.finditer
def finditer(self, expr): """Return an iterator over all matches in `expr` Iterate over all :class:`MatchDict` results of matches for any matching (sub-)expressions in `expr`. The order of the matches conforms to the equivalent matched expressions returned by :meth:`findall`. ""...
python
def finditer(self, expr): """Return an iterator over all matches in `expr` Iterate over all :class:`MatchDict` results of matches for any matching (sub-)expressions in `expr`. The order of the matches conforms to the equivalent matched expressions returned by :meth:`findall`. ""...
[ "def", "finditer", "(", "self", ",", "expr", ")", ":", "try", ":", "for", "arg", "in", "expr", ".", "args", ":", "for", "m", "in", "self", ".", "finditer", "(", "arg", ")", ":", "yield", "m", "for", "arg", "in", "expr", ".", "kwargs", ".", "val...
Return an iterator over all matches in `expr` Iterate over all :class:`MatchDict` results of matches for any matching (sub-)expressions in `expr`. The order of the matches conforms to the equivalent matched expressions returned by :meth:`findall`.
[ "Return", "an", "iterator", "over", "all", "matches", "in", "expr" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L370-L388
train
62,846
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
Pattern.wc_names
def wc_names(self): """Set of all wildcard names occurring in the pattern""" if self.wc_name is None: res = set() else: res = set([self.wc_name]) if self.args is not None: for arg in self.args: if isinstance(arg, Pattern): ...
python
def wc_names(self): """Set of all wildcard names occurring in the pattern""" if self.wc_name is None: res = set() else: res = set([self.wc_name]) if self.args is not None: for arg in self.args: if isinstance(arg, Pattern): ...
[ "def", "wc_names", "(", "self", ")", ":", "if", "self", ".", "wc_name", "is", "None", ":", "res", "=", "set", "(", ")", "else", ":", "res", "=", "set", "(", "[", "self", ".", "wc_name", "]", ")", "if", "self", ".", "args", "is", "not", "None", ...
Set of all wildcard names occurring in the pattern
[ "Set", "of", "all", "wildcard", "names", "occurring", "in", "the", "pattern" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L391-L405
train
62,847
mabuchilab/QNET
src/qnet/algebra/pattern_matching/__init__.py
ProtoExpr.from_expr
def from_expr(cls, expr): """Instantiate proto-expression from the given Expression""" return cls(expr.args, expr.kwargs, cls=expr.__class__)
python
def from_expr(cls, expr): """Instantiate proto-expression from the given Expression""" return cls(expr.args, expr.kwargs, cls=expr.__class__)
[ "def", "from_expr", "(", "cls", ",", "expr", ")", ":", "return", "cls", "(", "expr", ".", "args", ",", "expr", ".", "kwargs", ",", "cls", "=", "expr", ".", "__class__", ")" ]
Instantiate proto-expression from the given Expression
[ "Instantiate", "proto", "-", "expression", "from", "the", "given", "Expression" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L604-L606
train
62,848
django-fluent/django-fluent-blogs
fluent_blogs/models/db.py
get_entry_model
def get_entry_model(): """ Return the actual entry model that is in use. This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model. The model is automatically registered with *django-fluent-comments* and *django-any-urlfield* when it's installed. """ global _EntryMod...
python
def get_entry_model(): """ Return the actual entry model that is in use. This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model. The model is automatically registered with *django-fluent-comments* and *django-any-urlfield* when it's installed. """ global _EntryMod...
[ "def", "get_entry_model", "(", ")", ":", "global", "_EntryModel", "if", "_EntryModel", "is", "None", ":", "# This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used.", "# Either way, it needs to happen after all apps...
Return the actual entry model that is in use. This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model. The model is automatically registered with *django-fluent-comments* and *django-any-urlfield* when it's installed.
[ "Return", "the", "actual", "entry", "model", "that", "is", "in", "use", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/db.py#L43-L80
train
62,849
django-fluent/django-fluent-blogs
fluent_blogs/models/db.py
get_category_model
def get_category_model(): """ Return the category model to use. This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model. """ app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit('.', 1) try: return apps.get_model(app_label, model_name) ...
python
def get_category_model(): """ Return the category model to use. This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model. """ app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit('.', 1) try: return apps.get_model(app_label, model_name) ...
[ "def", "get_category_model", "(", ")", ":", "app_label", ",", "model_name", "=", "appsettings", ".", "FLUENT_BLOGS_CATEGORY_MODEL", ".", "rsplit", "(", "'.'", ",", "1", ")", "try", ":", "return", "apps", ".", "get_model", "(", "app_label", ",", "model_name", ...
Return the category model to use. This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model.
[ "Return", "the", "category", "model", "to", "use", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/db.py#L83-L95
train
62,850
django-fluent/django-fluent-blogs
fluent_blogs/urlresolvers.py
blog_reverse
def blog_reverse(viewname, args=None, kwargs=None, current_app='fluent_blogs', **page_kwargs): """ Reverse a URL to the blog, taking various configuration options into account. This is a compatibility function to allow django-fluent-blogs to operate stand-alone. Either the app can be hooked in the URLc...
python
def blog_reverse(viewname, args=None, kwargs=None, current_app='fluent_blogs', **page_kwargs): """ Reverse a URL to the blog, taking various configuration options into account. This is a compatibility function to allow django-fluent-blogs to operate stand-alone. Either the app can be hooked in the URLc...
[ "def", "blog_reverse", "(", "viewname", ",", "args", "=", "None", ",", "kwargs", "=", "None", ",", "current_app", "=", "'fluent_blogs'", ",", "*", "*", "page_kwargs", ")", ":", "return", "mixed_reverse", "(", "viewname", ",", "args", "=", "args", ",", "k...
Reverse a URL to the blog, taking various configuration options into account. This is a compatibility function to allow django-fluent-blogs to operate stand-alone. Either the app can be hooked in the URLconf directly, or it can be added as a pagetype of *django-fluent-pages*.
[ "Reverse", "a", "URL", "to", "the", "blog", "taking", "various", "configuration", "options", "into", "account", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/urlresolvers.py#L4-L11
train
62,851
mabuchilab/QNET
src/qnet/algebra/toolbox/commutator_manipulation.py
expand_commutators_leibniz
def expand_commutators_leibniz(expr, expand_expr=True): """Recursively expand commutators in `expr` according to the Leibniz rule. .. math:: [A B, C] = A [B, C] + [A, C] B .. math:: [A, B C] = [A, B] C + B [A, C] If `expand_expr` is True, expand products of sums in `expr`, as well a...
python
def expand_commutators_leibniz(expr, expand_expr=True): """Recursively expand commutators in `expr` according to the Leibniz rule. .. math:: [A B, C] = A [B, C] + [A, C] B .. math:: [A, B C] = [A, B] C + B [A, C] If `expand_expr` is True, expand products of sums in `expr`, as well a...
[ "def", "expand_commutators_leibniz", "(", "expr", ",", "expand_expr", "=", "True", ")", ":", "recurse", "=", "partial", "(", "expand_commutators_leibniz", ",", "expand_expr", "=", "expand_expr", ")", "A", "=", "wc", "(", "'A'", ",", "head", "=", "Operator", ...
Recursively expand commutators in `expr` according to the Leibniz rule. .. math:: [A B, C] = A [B, C] + [A, C] B .. math:: [A, B C] = [A, B] C + B [A, C] If `expand_expr` is True, expand products of sums in `expr`, as well as in the result.
[ "Recursively", "expand", "commutators", "in", "expr", "according", "to", "the", "Leibniz", "rule", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/toolbox/commutator_manipulation.py#L14-L58
train
62,852
mabuchilab/QNET
src/qnet/printing/__init__.py
init_printing
def init_printing(*, reset=False, init_sympy=True, **kwargs): """Initialize the printing system. This determines the behavior of the :func:`ascii`, :func:`unicode`, and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of any :class:`.Expression`. The routine may be called in on...
python
def init_printing(*, reset=False, init_sympy=True, **kwargs): """Initialize the printing system. This determines the behavior of the :func:`ascii`, :func:`unicode`, and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of any :class:`.Expression`. The routine may be called in on...
[ "def", "init_printing", "(", "*", ",", "reset", "=", "False", ",", "init_sympy", "=", "True", ",", "*", "*", "kwargs", ")", ":", "# return either None (default) or a dict of frozen attributes if", "# ``_freeze=True`` is given as a keyword argument (internal use in", "# `confi...
Initialize the printing system. This determines the behavior of the :func:`ascii`, :func:`unicode`, and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of any :class:`.Expression`. The routine may be called in one of two forms. First, :: init_printing( st...
[ "Initialize", "the", "printing", "system", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/printing/__init__.py#L47-L143
train
62,853
mabuchilab/QNET
src/qnet/printing/__init__.py
configure_printing
def configure_printing(**kwargs): """Context manager for temporarily changing the printing system. This takes the same parameters as :func:`init_printing` Example: >>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1) >>> with configure_printing(show_hs_label=False): .....
python
def configure_printing(**kwargs): """Context manager for temporarily changing the printing system. This takes the same parameters as :func:`init_printing` Example: >>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1) >>> with configure_printing(show_hs_label=False): .....
[ "def", "configure_printing", "(", "*", "*", "kwargs", ")", ":", "freeze", "=", "init_printing", "(", "_freeze", "=", "True", ",", "*", "*", "kwargs", ")", "try", ":", "yield", "finally", ":", "for", "obj", ",", "attr_map", "in", "freeze", ".", "items",...
Context manager for temporarily changing the printing system. This takes the same parameters as :func:`init_printing` Example: >>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1) >>> with configure_printing(show_hs_label=False): ... print(ascii(A + B)) A + B ...
[ "Context", "manager", "for", "temporarily", "changing", "the", "printing", "system", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/printing/__init__.py#L272-L292
train
62,854
mabuchilab/QNET
src/qnet/convert/to_qutip.py
convert_to_qutip
def convert_to_qutip(expr, full_space=None, mapping=None): """Convert a QNET expression to a qutip object Args: expr: a QNET expression full_space (HilbertSpace): The Hilbert space in which `expr` is defined. If not given, ``expr.space`` is used. The Hilbert space must h...
python
def convert_to_qutip(expr, full_space=None, mapping=None): """Convert a QNET expression to a qutip object Args: expr: a QNET expression full_space (HilbertSpace): The Hilbert space in which `expr` is defined. If not given, ``expr.space`` is used. The Hilbert space must h...
[ "def", "convert_to_qutip", "(", "expr", ",", "full_space", "=", "None", ",", "mapping", "=", "None", ")", ":", "if", "full_space", "is", "None", ":", "full_space", "=", "expr", ".", "space", "if", "not", "expr", ".", "space", ".", "is_tensor_factor_of", ...
Convert a QNET expression to a qutip object Args: expr: a QNET expression full_space (HilbertSpace): The Hilbert space in which `expr` is defined. If not given, ``expr.space`` is used. The Hilbert space must have a well-defined basis. mapping (dict): A ma...
[ "Convert", "a", "QNET", "expression", "to", "a", "qutip", "object" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L44-L118
train
62,855
mabuchilab/QNET
src/qnet/convert/to_qutip.py
_convert_local_operator_to_qutip
def _convert_local_operator_to_qutip(expr, full_space, mapping): """Convert a LocalOperator instance to qutip""" n = full_space.dimension if full_space != expr.space: all_spaces = full_space.local_factors own_space_index = all_spaces.index(expr.space) return qutip.tensor( ...
python
def _convert_local_operator_to_qutip(expr, full_space, mapping): """Convert a LocalOperator instance to qutip""" n = full_space.dimension if full_space != expr.space: all_spaces = full_space.local_factors own_space_index = all_spaces.index(expr.space) return qutip.tensor( ...
[ "def", "_convert_local_operator_to_qutip", "(", "expr", ",", "full_space", ",", "mapping", ")", ":", "n", "=", "full_space", ".", "dimension", "if", "full_space", "!=", "expr", ".", "space", ":", "all_spaces", "=", "full_space", ".", "local_factors", "own_space_...
Convert a LocalOperator instance to qutip
[ "Convert", "a", "LocalOperator", "instance", "to", "qutip" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L181-L226
train
62,856
mabuchilab/QNET
src/qnet/convert/to_qutip.py
_time_dependent_to_qutip
def _time_dependent_to_qutip( op, full_space=None, time_symbol=symbols("t", real=True), convert_as='pyfunc'): """Convert a possiblty time-dependent operator into the nested-list structure required by QuTiP""" if full_space is None: full_space = op.space if time_symbol in op.free_...
python
def _time_dependent_to_qutip( op, full_space=None, time_symbol=symbols("t", real=True), convert_as='pyfunc'): """Convert a possiblty time-dependent operator into the nested-list structure required by QuTiP""" if full_space is None: full_space = op.space if time_symbol in op.free_...
[ "def", "_time_dependent_to_qutip", "(", "op", ",", "full_space", "=", "None", ",", "time_symbol", "=", "symbols", "(", "\"t\"", ",", "real", "=", "True", ")", ",", "convert_as", "=", "'pyfunc'", ")", ":", "if", "full_space", "is", "None", ":", "full_space"...
Convert a possiblty time-dependent operator into the nested-list structure required by QuTiP
[ "Convert", "a", "possiblty", "time", "-", "dependent", "operator", "into", "the", "nested", "-", "list", "structure", "required", "by", "QuTiP" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L412-L463
train
62,857
mabuchilab/QNET
src/qnet/utils/unicode.py
ljust
def ljust(text, width, fillchar=' '): """Left-justify text to a total of `width` The `width` is based on graphemes:: >>> s = 'Â' >>> s.ljust(2) 'Â' >>> ljust(s, 2) 'Â ' """ len_text = grapheme_len(text) return text + fillchar * (width - len_text)
python
def ljust(text, width, fillchar=' '): """Left-justify text to a total of `width` The `width` is based on graphemes:: >>> s = 'Â' >>> s.ljust(2) 'Â' >>> ljust(s, 2) 'Â ' """ len_text = grapheme_len(text) return text + fillchar * (width - len_text)
[ "def", "ljust", "(", "text", ",", "width", ",", "fillchar", "=", "' '", ")", ":", "len_text", "=", "grapheme_len", "(", "text", ")", "return", "text", "+", "fillchar", "*", "(", "width", "-", "len_text", ")" ]
Left-justify text to a total of `width` The `width` is based on graphemes:: >>> s = 'Â' >>> s.ljust(2) 'Â' >>> ljust(s, 2) 'Â '
[ "Left", "-", "justify", "text", "to", "a", "total", "of", "width" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/unicode.py#L21-L33
train
62,858
mabuchilab/QNET
src/qnet/utils/unicode.py
rjust
def rjust(text, width, fillchar=' '): """Right-justify text for a total of `width` graphemes The `width` is based on graphemes:: >>> s = 'Â' >>> s.rjust(2) 'Â' >>> rjust(s, 2) ' Â' """ len_text = grapheme_len(text) return fillchar * (width - len_text) + t...
python
def rjust(text, width, fillchar=' '): """Right-justify text for a total of `width` graphemes The `width` is based on graphemes:: >>> s = 'Â' >>> s.rjust(2) 'Â' >>> rjust(s, 2) ' Â' """ len_text = grapheme_len(text) return fillchar * (width - len_text) + t...
[ "def", "rjust", "(", "text", ",", "width", ",", "fillchar", "=", "' '", ")", ":", "len_text", "=", "grapheme_len", "(", "text", ")", "return", "fillchar", "*", "(", "width", "-", "len_text", ")", "+", "text" ]
Right-justify text for a total of `width` graphemes The `width` is based on graphemes:: >>> s = 'Â' >>> s.rjust(2) 'Â' >>> rjust(s, 2) ' Â'
[ "Right", "-", "justify", "text", "for", "a", "total", "of", "width", "graphemes" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/unicode.py#L36-L48
train
62,859
mabuchilab/QNET
src/qnet/algebra/core/scalar_algebra.py
KroneckerDelta
def KroneckerDelta(i, j, simplify=True): """Kronecker delta symbol Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's :class:`~sympy.functions.special.tensor_functions.KroneckerDelta`. >>> i, j = IdxSym('i'...
python
def KroneckerDelta(i, j, simplify=True): """Kronecker delta symbol Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's :class:`~sympy.functions.special.tensor_functions.KroneckerDelta`. >>> i, j = IdxSym('i'...
[ "def", "KroneckerDelta", "(", "i", ",", "j", ",", "simplify", "=", "True", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "scalar_algebra", "import", "ScalarValue", ",", "One", "if", "not", "isinstance", "(", "i", ",", "(", "int", ",", "...
Kronecker delta symbol Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's :class:`~sympy.functions.special.tensor_functions.KroneckerDelta`. >>> i, j = IdxSym('i'), IdxSym('j') >>> KroneckerDelta(i, i) ...
[ "Kronecker", "delta", "symbol" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L1106-L1148
train
62,860
mabuchilab/QNET
src/qnet/algebra/core/scalar_algebra.py
ScalarTimes.create
def create(cls, *operands, **kwargs): """Instantiate the product while applying simplification rules""" converted_operands = [] for op in operands: if not isinstance(op, Scalar): op = ScalarValue.create(op) converted_operands.append(op) return supe...
python
def create(cls, *operands, **kwargs): """Instantiate the product while applying simplification rules""" converted_operands = [] for op in operands: if not isinstance(op, Scalar): op = ScalarValue.create(op) converted_operands.append(op) return supe...
[ "def", "create", "(", "cls", ",", "*", "operands", ",", "*", "*", "kwargs", ")", ":", "converted_operands", "=", "[", "]", "for", "op", "in", "operands", ":", "if", "not", "isinstance", "(", "op", ",", "Scalar", ")", ":", "op", "=", "ScalarValue", ...
Instantiate the product while applying simplification rules
[ "Instantiate", "the", "product", "while", "applying", "simplification", "rules" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L898-L905
train
62,861
mabuchilab/QNET
src/qnet/algebra/core/scalar_algebra.py
ScalarTimes.conjugate
def conjugate(self): """Complex conjugate of of the product""" return self.__class__.create( *[arg.conjugate() for arg in reversed(self.args)])
python
def conjugate(self): """Complex conjugate of of the product""" return self.__class__.create( *[arg.conjugate() for arg in reversed(self.args)])
[ "def", "conjugate", "(", "self", ")", ":", "return", "self", ".", "__class__", ".", "create", "(", "*", "[", "arg", ".", "conjugate", "(", ")", "for", "arg", "in", "reversed", "(", "self", ".", "args", ")", "]", ")" ]
Complex conjugate of of the product
[ "Complex", "conjugate", "of", "of", "the", "product" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L907-L910
train
62,862
mabuchilab/QNET
src/qnet/algebra/core/scalar_algebra.py
ScalarIndexedSum.create
def create(cls, term, *ranges): """Instantiate the indexed sum while applying simplification rules""" if not isinstance(term, Scalar): term = ScalarValue.create(term) return super().create(term, *ranges)
python
def create(cls, term, *ranges): """Instantiate the indexed sum while applying simplification rules""" if not isinstance(term, Scalar): term = ScalarValue.create(term) return super().create(term, *ranges)
[ "def", "create", "(", "cls", ",", "term", ",", "*", "ranges", ")", ":", "if", "not", "isinstance", "(", "term", ",", "Scalar", ")", ":", "term", "=", "ScalarValue", ".", "create", "(", "term", ")", "return", "super", "(", ")", ".", "create", "(", ...
Instantiate the indexed sum while applying simplification rules
[ "Instantiate", "the", "indexed", "sum", "while", "applying", "simplification", "rules" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L950-L954
train
62,863
mabuchilab/QNET
src/qnet/algebra/core/scalar_algebra.py
ScalarIndexedSum.conjugate
def conjugate(self): """Complex conjugate of of the indexed sum""" return self.__class__.create(self.term.conjugate(), *self.ranges)
python
def conjugate(self): """Complex conjugate of of the indexed sum""" return self.__class__.create(self.term.conjugate(), *self.ranges)
[ "def", "conjugate", "(", "self", ")", ":", "return", "self", ".", "__class__", ".", "create", "(", "self", ".", "term", ".", "conjugate", "(", ")", ",", "*", "self", ".", "ranges", ")" ]
Complex conjugate of of the indexed sum
[ "Complex", "conjugate", "of", "of", "the", "indexed", "sum" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L961-L963
train
62,864
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
collect_summands
def collect_summands(cls, ops, kwargs): """Collect summands that occur multiple times into a single summand Also filters out zero-summands. Example: >>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C')) >>> collect_summands( ... OperatorPlus, (A, B, C, ZeroOperator, ...
python
def collect_summands(cls, ops, kwargs): """Collect summands that occur multiple times into a single summand Also filters out zero-summands. Example: >>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C')) >>> collect_summands( ... OperatorPlus, (A, B, C, ZeroOperator, ...
[ "def", "collect_summands", "(", "cls", ",", "ops", ",", "kwargs", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra", "import", "(", "ScalarTimesQuantumExpression", ")", "coeff_map", "=", "OrderedDict", "(", ")", "for", "op"...
Collect summands that occur multiple times into a single summand Also filters out zero-summands. Example: >>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C')) >>> collect_summands( ... OperatorPlus, (A, B, C, ZeroOperator, 2 * A, B, -C) , {}) ((3 * A^(0), 2 * B^...
[ "Collect", "summands", "that", "occur", "multiple", "times", "into", "a", "single", "summand" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L147-L184
train
62,865
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_get_binary_replacement
def _get_binary_replacement(first, second, cls): """Helper function for match_replace_binary""" expr = ProtoExpr([first, second], {}) if LOG: logger = logging.getLogger('QNET.create') for key, rule in cls._binary_rules.items(): pat, replacement = rule match_dict = match_pattern(p...
python
def _get_binary_replacement(first, second, cls): """Helper function for match_replace_binary""" expr = ProtoExpr([first, second], {}) if LOG: logger = logging.getLogger('QNET.create') for key, rule in cls._binary_rules.items(): pat, replacement = rule match_dict = match_pattern(p...
[ "def", "_get_binary_replacement", "(", "first", ",", "second", ",", "cls", ")", ":", "expr", "=", "ProtoExpr", "(", "[", "first", ",", "second", "]", ",", "{", "}", ")", "if", "LOG", ":", "logger", "=", "logging", ".", "getLogger", "(", "'QNET.create'"...
Helper function for match_replace_binary
[ "Helper", "function", "for", "match_replace_binary" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L323-L350
train
62,866
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_match_replace_binary
def _match_replace_binary(cls, ops: list) -> list: """Reduce list of `ops`""" n = len(ops) if n <= 1: return ops ops_left = ops[:n // 2] ops_right = ops[n // 2:] return _match_replace_binary_combine( cls, _match_replace_binary(cls, ops_left), _match_replace_binary...
python
def _match_replace_binary(cls, ops: list) -> list: """Reduce list of `ops`""" n = len(ops) if n <= 1: return ops ops_left = ops[:n // 2] ops_right = ops[n // 2:] return _match_replace_binary_combine( cls, _match_replace_binary(cls, ops_left), _match_replace_binary...
[ "def", "_match_replace_binary", "(", "cls", ",", "ops", ":", "list", ")", "->", "list", ":", "n", "=", "len", "(", "ops", ")", "if", "n", "<=", "1", ":", "return", "ops", "ops_left", "=", "ops", "[", ":", "n", "//", "2", "]", "ops_right", "=", ...
Reduce list of `ops`
[ "Reduce", "list", "of", "ops" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L392-L402
train
62,867
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_match_replace_binary_combine
def _match_replace_binary_combine(cls, a: list, b: list) -> list: """combine two fully reduced lists a, b""" if len(a) == 0 or len(b) == 0: return a + b r = _get_binary_replacement(a[-1], b[0], cls) if r is None: return a + b if r == cls._neutral_element: return _match_replac...
python
def _match_replace_binary_combine(cls, a: list, b: list) -> list: """combine two fully reduced lists a, b""" if len(a) == 0 or len(b) == 0: return a + b r = _get_binary_replacement(a[-1], b[0], cls) if r is None: return a + b if r == cls._neutral_element: return _match_replac...
[ "def", "_match_replace_binary_combine", "(", "cls", ",", "a", ":", "list", ",", "b", ":", "list", ")", "->", "list", ":", "if", "len", "(", "a", ")", "==", "0", "or", "len", "(", "b", ")", "==", "0", ":", "return", "a", "+", "b", "r", "=", "_...
combine two fully reduced lists a, b
[ "combine", "two", "fully", "reduced", "lists", "a", "b" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L405-L421
train
62,868
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
empty_trivial
def empty_trivial(cls, ops, kwargs): """A ProductSpace of zero Hilbert spaces should yield the TrivialSpace""" from qnet.algebra.core.hilbert_space_algebra import TrivialSpace if len(ops) == 0: return TrivialSpace else: return ops, kwargs
python
def empty_trivial(cls, ops, kwargs): """A ProductSpace of zero Hilbert spaces should yield the TrivialSpace""" from qnet.algebra.core.hilbert_space_algebra import TrivialSpace if len(ops) == 0: return TrivialSpace else: return ops, kwargs
[ "def", "empty_trivial", "(", "cls", ",", "ops", ",", "kwargs", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "hilbert_space_algebra", "import", "TrivialSpace", "if", "len", "(", "ops", ")", "==", "0", ":", "return", "TrivialSpace", "else", ...
A ProductSpace of zero Hilbert spaces should yield the TrivialSpace
[ "A", "ProductSpace", "of", "zero", "Hilbert", "spaces", "should", "yield", "the", "TrivialSpace" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L460-L466
train
62,869
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
disjunct_hs_zero
def disjunct_hs_zero(cls, ops, kwargs): """Return ZeroOperator if all the operators in `ops` have a disjunct Hilbert space, or an unchanged `ops`, `kwargs` otherwise """ from qnet.algebra.core.hilbert_space_algebra import TrivialSpace from qnet.algebra.core.operator_algebra import ZeroOperator h...
python
def disjunct_hs_zero(cls, ops, kwargs): """Return ZeroOperator if all the operators in `ops` have a disjunct Hilbert space, or an unchanged `ops`, `kwargs` otherwise """ from qnet.algebra.core.hilbert_space_algebra import TrivialSpace from qnet.algebra.core.operator_algebra import ZeroOperator h...
[ "def", "disjunct_hs_zero", "(", "cls", ",", "ops", ",", "kwargs", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "hilbert_space_algebra", "import", "TrivialSpace", "from", "qnet", ".", "algebra", ".", "core", ".", "operator_algebra", "import", "...
Return ZeroOperator if all the operators in `ops` have a disjunct Hilbert space, or an unchanged `ops`, `kwargs` otherwise
[ "Return", "ZeroOperator", "if", "all", "the", "operators", "in", "ops", "have", "a", "disjunct", "Hilbert", "space", "or", "an", "unchanged", "ops", "kwargs", "otherwise" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L576-L592
train
62,870
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
commutator_order
def commutator_order(cls, ops, kwargs): """Apply anti-commutative property of the commutator to apply a standard ordering of the commutator arguments """ from qnet.algebra.core.operator_algebra import Commutator assert len(ops) == 2 if cls.order_key(ops[1]) < cls.order_key(ops[0]): retur...
python
def commutator_order(cls, ops, kwargs): """Apply anti-commutative property of the commutator to apply a standard ordering of the commutator arguments """ from qnet.algebra.core.operator_algebra import Commutator assert len(ops) == 2 if cls.order_key(ops[1]) < cls.order_key(ops[0]): retur...
[ "def", "commutator_order", "(", "cls", ",", "ops", ",", "kwargs", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "operator_algebra", "import", "Commutator", "assert", "len", "(", "ops", ")", "==", "2", "if", "cls", ".", "order_key", "(", "...
Apply anti-commutative property of the commutator to apply a standard ordering of the commutator arguments
[ "Apply", "anti", "-", "commutative", "property", "of", "the", "commutator", "to", "apply", "a", "standard", "ordering", "of", "the", "commutator", "arguments" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L595-L604
train
62,871
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
accept_bras
def accept_bras(cls, ops, kwargs): """Accept operands that are all bras, and turn that into to bra of the operation applied to all corresponding kets""" from qnet.algebra.core.state_algebra import Bra kets = [] for bra in ops: if isinstance(bra, Bra): kets.append(bra.ket) ...
python
def accept_bras(cls, ops, kwargs): """Accept operands that are all bras, and turn that into to bra of the operation applied to all corresponding kets""" from qnet.algebra.core.state_algebra import Bra kets = [] for bra in ops: if isinstance(bra, Bra): kets.append(bra.ket) ...
[ "def", "accept_bras", "(", "cls", ",", "ops", ",", "kwargs", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "state_algebra", "import", "Bra", "kets", "=", "[", "]", "for", "bra", "in", "ops", ":", "if", "isinstance", "(", "bra", ",", "...
Accept operands that are all bras, and turn that into to bra of the operation applied to all corresponding kets
[ "Accept", "operands", "that", "are", "all", "bras", "and", "turn", "that", "into", "to", "bra", "of", "the", "operation", "applied", "to", "all", "corresponding", "kets" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L607-L617
train
62,872
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_ranges_key
def _ranges_key(r, delta_indices): """Sorting key for ranges. When used with ``reverse=True``, this can be used to sort index ranges into the order we would prefer to eliminate them by evaluating KroneckerDeltas: First, eliminate primed indices, then indices names higher in the alphabet. """ id...
python
def _ranges_key(r, delta_indices): """Sorting key for ranges. When used with ``reverse=True``, this can be used to sort index ranges into the order we would prefer to eliminate them by evaluating KroneckerDeltas: First, eliminate primed indices, then indices names higher in the alphabet. """ id...
[ "def", "_ranges_key", "(", "r", ",", "delta_indices", ")", ":", "idx", "=", "r", ".", "index_symbol", "if", "idx", "in", "delta_indices", ":", "return", "(", "r", ".", "index_symbol", ".", "primed", ",", "r", ".", "index_symbol", ".", "name", ")", "els...
Sorting key for ranges. When used with ``reverse=True``, this can be used to sort index ranges into the order we would prefer to eliminate them by evaluating KroneckerDeltas: First, eliminate primed indices, then indices names higher in the alphabet.
[ "Sorting", "key", "for", "ranges", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L666-L679
train
62,873
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_factors_for_expand_delta
def _factors_for_expand_delta(expr): """Yield factors from expr, mixing sympy and QNET Auxiliary routine for :func:`_expand_delta`. """ from qnet.algebra.core.scalar_algebra import ScalarValue from qnet.algebra.core.abstract_quantum_algebra import ( ScalarTimesQuantumExpression) if isin...
python
def _factors_for_expand_delta(expr): """Yield factors from expr, mixing sympy and QNET Auxiliary routine for :func:`_expand_delta`. """ from qnet.algebra.core.scalar_algebra import ScalarValue from qnet.algebra.core.abstract_quantum_algebra import ( ScalarTimesQuantumExpression) if isin...
[ "def", "_factors_for_expand_delta", "(", "expr", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "scalar_algebra", "import", "ScalarValue", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra", "import", "(", "ScalarTimesQuantum...
Yield factors from expr, mixing sympy and QNET Auxiliary routine for :func:`_expand_delta`.
[ "Yield", "factors", "from", "expr", "mixing", "sympy", "and", "QNET" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L740-L756
train
62,874
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_split_sympy_quantum_factor
def _split_sympy_quantum_factor(expr): """Split a product into sympy and qnet factors This is a helper routine for applying some sympy transformation on an arbitrary product-like expression in QNET. The idea is this:: expr -> sympy_factor, quantum_factor sympy_factor -> sympy_function(symp...
python
def _split_sympy_quantum_factor(expr): """Split a product into sympy and qnet factors This is a helper routine for applying some sympy transformation on an arbitrary product-like expression in QNET. The idea is this:: expr -> sympy_factor, quantum_factor sympy_factor -> sympy_function(symp...
[ "def", "_split_sympy_quantum_factor", "(", "expr", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra", "import", "(", "QuantumExpression", ",", "ScalarTimesQuantumExpression", ")", "from", "qnet", ".", "algebra", ".", "core", "....
Split a product into sympy and qnet factors This is a helper routine for applying some sympy transformation on an arbitrary product-like expression in QNET. The idea is this:: expr -> sympy_factor, quantum_factor sympy_factor -> sympy_function(sympy_factor) expr -> sympy_factor * quant...
[ "Split", "a", "product", "into", "sympy", "and", "qnet", "factors" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L793-L827
train
62,875
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_extract_delta
def _extract_delta(expr, idx): """Extract a "simple" Kronecker delta containing `idx` from `expr`. Assuming `expr` can be written as the product of a Kronecker Delta and a `new_expr`, return a tuple of the sympy.KroneckerDelta instance and `new_expr`. Otherwise, return a tuple of None and the original ...
python
def _extract_delta(expr, idx): """Extract a "simple" Kronecker delta containing `idx` from `expr`. Assuming `expr` can be written as the product of a Kronecker Delta and a `new_expr`, return a tuple of the sympy.KroneckerDelta instance and `new_expr`. Otherwise, return a tuple of None and the original ...
[ "def", "_extract_delta", "(", "expr", ",", "idx", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra", "import", "QuantumExpression", "from", "qnet", ".", "algebra", ".", "core", ".", "scalar_algebra", "import", "ScalarValue", ...
Extract a "simple" Kronecker delta containing `idx` from `expr`. Assuming `expr` can be written as the product of a Kronecker Delta and a `new_expr`, return a tuple of the sympy.KroneckerDelta instance and `new_expr`. Otherwise, return a tuple of None and the original `expr` (possibly converted to a :c...
[ "Extract", "a", "simple", "Kronecker", "delta", "containing", "idx", "from", "expr", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L830-L853
train
62,876
mabuchilab/QNET
src/qnet/algebra/core/algebraic_properties.py
_deltasummation
def _deltasummation(term, ranges, i_range): """Partially execute a summation for `term` with a Kronecker Delta for one of the summation indices. This implements the solution to the core sub-problem in :func:`indexed_sum_over_kronecker` Args: term (QuantumExpression): term of the sum ...
python
def _deltasummation(term, ranges, i_range): """Partially execute a summation for `term` with a Kronecker Delta for one of the summation indices. This implements the solution to the core sub-problem in :func:`indexed_sum_over_kronecker` Args: term (QuantumExpression): term of the sum ...
[ "def", "_deltasummation", "(", "term", ",", "ranges", ",", "i_range", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "abstract_quantum_algebra", "import", "QuantumExpression", "idx", "=", "ranges", "[", "i_range", "]", ".", "index_symbol", "summan...
Partially execute a summation for `term` with a Kronecker Delta for one of the summation indices. This implements the solution to the core sub-problem in :func:`indexed_sum_over_kronecker` Args: term (QuantumExpression): term of the sum ranges (list): list of all summation index ranges...
[ "Partially", "execute", "a", "summation", "for", "term", "with", "a", "Kronecker", "Delta", "for", "one", "of", "the", "summation", "indices", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L856-L944
train
62,877
mabuchilab/QNET
src/qnet/utils/permutations.py
invert_permutation
def invert_permutation(permutation): """Compute the image tuple of the inverse permutation. :param permutation: A valid (cf. :py:func:check_permutation) permutation. :return: The inverse permutation tuple :rtype: tuple """ return tuple([permutation.index(p) for p in range(len(permutation))])
python
def invert_permutation(permutation): """Compute the image tuple of the inverse permutation. :param permutation: A valid (cf. :py:func:check_permutation) permutation. :return: The inverse permutation tuple :rtype: tuple """ return tuple([permutation.index(p) for p in range(len(permutation))])
[ "def", "invert_permutation", "(", "permutation", ")", ":", "return", "tuple", "(", "[", "permutation", ".", "index", "(", "p", ")", "for", "p", "in", "range", "(", "len", "(", "permutation", ")", ")", "]", ")" ]
Compute the image tuple of the inverse permutation. :param permutation: A valid (cf. :py:func:check_permutation) permutation. :return: The inverse permutation tuple :rtype: tuple
[ "Compute", "the", "image", "tuple", "of", "the", "inverse", "permutation", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L32-L39
train
62,878
mabuchilab/QNET
src/qnet/utils/permutations.py
permutation_to_block_permutations
def permutation_to_block_permutations(permutation): """If possible, decompose a permutation into a sequence of permutations each acting on individual ranges of the full range of indices. E.g. ``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)`` :param permutation: A valid permutation image tuple ``s = (s...
python
def permutation_to_block_permutations(permutation): """If possible, decompose a permutation into a sequence of permutations each acting on individual ranges of the full range of indices. E.g. ``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)`` :param permutation: A valid permutation image tuple ``s = (s...
[ "def", "permutation_to_block_permutations", "(", "permutation", ")", ":", "if", "len", "(", "permutation", ")", "==", "0", "or", "not", "check_permutation", "(", "permutation", ")", ":", "raise", "BadPermutationError", "(", ")", "cycles", "=", "permutation_to_disj...
If possible, decompose a permutation into a sequence of permutations each acting on individual ranges of the full range of indices. E.g. ``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)`` :param permutation: A valid permutation image tuple ``s = (s_0,...s_n)`` with ``n > 0`` :type permutation: tuple ...
[ "If", "possible", "decompose", "a", "permutation", "into", "a", "sequence", "of", "permutations", "each", "acting", "on", "individual", "ranges", "of", "the", "full", "range", "of", "indices", ".", "E", ".", "g", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L122-L163
train
62,879
mabuchilab/QNET
src/qnet/utils/permutations.py
block_perm_and_perms_within_blocks
def block_perm_and_perms_within_blocks(permutation, block_structure): """Decompose a permutation into a block permutation and into permutations acting within each block. :param permutation: The overall permutation to be factored. :type permutation: tuple :param block_structure: The channel dimensio...
python
def block_perm_and_perms_within_blocks(permutation, block_structure): """Decompose a permutation into a block permutation and into permutations acting within each block. :param permutation: The overall permutation to be factored. :type permutation: tuple :param block_structure: The channel dimensio...
[ "def", "block_perm_and_perms_within_blocks", "(", "permutation", ",", "block_structure", ")", ":", "nblocks", "=", "len", "(", "block_structure", ")", "offsets", "=", "[", "sum", "(", "block_structure", "[", ":", "k", "]", ")", "for", "k", "in", "range", "("...
Decompose a permutation into a block permutation and into permutations acting within each block. :param permutation: The overall permutation to be factored. :type permutation: tuple :param block_structure: The channel dimensions of the blocks :type block_structure: tuple :return: ``(block_permu...
[ "Decompose", "a", "permutation", "into", "a", "block", "permutation", "and", "into", "permutations", "acting", "within", "each", "block", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L269-L312
train
62,880
mabuchilab/QNET
src/qnet/algebra/core/state_algebra.py
_check_kets
def _check_kets(*ops, same_space=False, disjunct_space=False): """Check that all operands are Kets from the same Hilbert space.""" if not all([(isinstance(o, State) and o.isket) for o in ops]): raise TypeError("All operands must be Kets") if same_space: if not len({o.space for o in ops if o ...
python
def _check_kets(*ops, same_space=False, disjunct_space=False): """Check that all operands are Kets from the same Hilbert space.""" if not all([(isinstance(o, State) and o.isket) for o in ops]): raise TypeError("All operands must be Kets") if same_space: if not len({o.space for o in ops if o ...
[ "def", "_check_kets", "(", "*", "ops", ",", "same_space", "=", "False", ",", "disjunct_space", "=", "False", ")", ":", "if", "not", "all", "(", "[", "(", "isinstance", "(", "o", ",", "State", ")", "and", "o", ".", "isket", ")", "for", "o", "in", ...
Check that all operands are Kets from the same Hilbert space.
[ "Check", "that", "all", "operands", "are", "Kets", "from", "the", "same", "Hilbert", "space", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L732-L744
train
62,881
mabuchilab/QNET
src/qnet/algebra/core/state_algebra.py
BasisKet.args
def args(self): """Tuple containing `label_or_index` as its only element.""" if self.space.has_basis or isinstance(self.label, SymbolicLabelBase): return (self.label, ) else: return (self.index, )
python
def args(self): """Tuple containing `label_or_index` as its only element.""" if self.space.has_basis or isinstance(self.label, SymbolicLabelBase): return (self.label, ) else: return (self.index, )
[ "def", "args", "(", "self", ")", ":", "if", "self", ".", "space", ".", "has_basis", "or", "isinstance", "(", "self", ".", "label", ",", "SymbolicLabelBase", ")", ":", "return", "(", "self", ".", "label", ",", ")", "else", ":", "return", "(", "self", ...
Tuple containing `label_or_index` as its only element.
[ "Tuple", "containing", "label_or_index", "as", "its", "only", "element", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L291-L296
train
62,882
mabuchilab/QNET
src/qnet/algebra/core/state_algebra.py
CoherentStateKet.to_fock_representation
def to_fock_representation(self, index_symbol='n', max_terms=None): """Return the coherent state written out as an indexed sum over Fock basis states""" phase_factor = sympy.exp( sympy.Rational(-1, 2) * self.ampl * self.ampl.conjugate()) if not isinstance(index_symbol, IdxSym...
python
def to_fock_representation(self, index_symbol='n', max_terms=None): """Return the coherent state written out as an indexed sum over Fock basis states""" phase_factor = sympy.exp( sympy.Rational(-1, 2) * self.ampl * self.ampl.conjugate()) if not isinstance(index_symbol, IdxSym...
[ "def", "to_fock_representation", "(", "self", ",", "index_symbol", "=", "'n'", ",", "max_terms", "=", "None", ")", ":", "phase_factor", "=", "sympy", ".", "exp", "(", "sympy", ".", "Rational", "(", "-", "1", ",", "2", ")", "*", "self", ".", "ampl", "...
Return the coherent state written out as an indexed sum over Fock basis states
[ "Return", "the", "coherent", "state", "written", "out", "as", "an", "indexed", "sum", "over", "Fock", "basis", "states" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L398-L413
train
62,883
sveetch/djangocodemirror
djangocodemirror/widgets.py
CodeMirrorWidget.codemirror_script
def codemirror_script(self, inputid): """ Build CodeMirror HTML script tag which contains CodeMirror init. Arguments: inputid (string): Input id. Returns: string: HTML for field CodeMirror instance. """ varname = "{}_codemirror".format(inputid) ...
python
def codemirror_script(self, inputid): """ Build CodeMirror HTML script tag which contains CodeMirror init. Arguments: inputid (string): Input id. Returns: string: HTML for field CodeMirror instance. """ varname = "{}_codemirror".format(inputid) ...
[ "def", "codemirror_script", "(", "self", ",", "inputid", ")", ":", "varname", "=", "\"{}_codemirror\"", ".", "format", "(", "inputid", ")", "html", "=", "self", ".", "get_codemirror_field_js", "(", ")", "opts", "=", "self", ".", "codemirror_config", "(", ")"...
Build CodeMirror HTML script tag which contains CodeMirror init. Arguments: inputid (string): Input id. Returns: string: HTML for field CodeMirror instance.
[ "Build", "CodeMirror", "HTML", "script", "tag", "which", "contains", "CodeMirror", "init", "." ]
7d556eec59861b2f619398e837bdd089b3a8a7d7
https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/widgets.py#L75-L90
train
62,884
mabuchilab/QNET
src/qnet/algebra/_rules.py
_algebraic_rules_scalar
def _algebraic_rules_scalar(): """Set the default algebraic rules for scalars""" a = wc("a", head=SCALAR_VAL_TYPES) b = wc("b", head=SCALAR_VAL_TYPES) x = wc("x", head=SCALAR_TYPES) y = wc("y", head=SCALAR_TYPES) z = wc("z", head=SCALAR_TYPES) indranges__ = wc("indranges__", head=IndexRange...
python
def _algebraic_rules_scalar(): """Set the default algebraic rules for scalars""" a = wc("a", head=SCALAR_VAL_TYPES) b = wc("b", head=SCALAR_VAL_TYPES) x = wc("x", head=SCALAR_TYPES) y = wc("y", head=SCALAR_TYPES) z = wc("z", head=SCALAR_TYPES) indranges__ = wc("indranges__", head=IndexRange...
[ "def", "_algebraic_rules_scalar", "(", ")", ":", "a", "=", "wc", "(", "\"a\"", ",", "head", "=", "SCALAR_VAL_TYPES", ")", "b", "=", "wc", "(", "\"b\"", ",", "head", "=", "SCALAR_VAL_TYPES", ")", "x", "=", "wc", "(", "\"x\"", ",", "head", "=", "SCALAR...
Set the default algebraic rules for scalars
[ "Set", "the", "default", "algebraic", "rules", "for", "scalars" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L42-L105
train
62,885
mabuchilab/QNET
src/qnet/algebra/_rules.py
_tensor_decompose_series
def _tensor_decompose_series(lhs, rhs): """Simplification method for lhs << rhs Decompose a series product of two reducible circuits with compatible block structures into a concatenation of individual series products between subblocks. This method raises CannotSimplify when rhs is a CPermutation in ...
python
def _tensor_decompose_series(lhs, rhs): """Simplification method for lhs << rhs Decompose a series product of two reducible circuits with compatible block structures into a concatenation of individual series products between subblocks. This method raises CannotSimplify when rhs is a CPermutation in ...
[ "def", "_tensor_decompose_series", "(", "lhs", ",", "rhs", ")", ":", "if", "isinstance", "(", "rhs", ",", "CPermutation", ")", ":", "raise", "CannotSimplify", "(", ")", "lhs_structure", "=", "lhs", ".", "block_structure", "rhs_structure", "=", "rhs", ".", "b...
Simplification method for lhs << rhs Decompose a series product of two reducible circuits with compatible block structures into a concatenation of individual series products between subblocks. This method raises CannotSimplify when rhs is a CPermutation in order not to conflict with other _rules.
[ "Simplification", "method", "for", "lhs", "<<", "rhs" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L867-L887
train
62,886
mabuchilab/QNET
src/qnet/algebra/_rules.py
_factor_permutation_for_blocks
def _factor_permutation_for_blocks(cperm, rhs): """Simplification method for cperm << rhs. Decompose a series product of a channel permutation and a reducible circuit with appropriate block structure by decomposing the permutation into a permutation within each block of rhs and a block permutation and a...
python
def _factor_permutation_for_blocks(cperm, rhs): """Simplification method for cperm << rhs. Decompose a series product of a channel permutation and a reducible circuit with appropriate block structure by decomposing the permutation into a permutation within each block of rhs and a block permutation and a...
[ "def", "_factor_permutation_for_blocks", "(", "cperm", ",", "rhs", ")", ":", "rbs", "=", "rhs", ".", "block_structure", "if", "rhs", "==", "cid", "(", "rhs", ".", "cdim", ")", ":", "return", "cperm", "if", "len", "(", "rbs", ")", ">", "1", ":", "resi...
Simplification method for cperm << rhs. Decompose a series product of a channel permutation and a reducible circuit with appropriate block structure by decomposing the permutation into a permutation within each block of rhs and a block permutation and a residual part. This allows for achieving somethin...
[ "Simplification", "method", "for", "cperm", "<<", "rhs", ".", "Decompose", "a", "series", "product", "of", "a", "channel", "permutation", "and", "a", "reducible", "circuit", "with", "appropriate", "block", "structure", "by", "decomposing", "the", "permutation", ...
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L890-L908
train
62,887
mabuchilab/QNET
src/qnet/algebra/_rules.py
_pull_out_perm_lhs
def _pull_out_perm_lhs(lhs, rest, out_port, in_port): """Pull out a permutation from the Feedback of a SeriesProduct with itself. Args: lhs (CPermutation): The permutation circuit rest (tuple): The other SeriesProduct operands out_port (int): The feedback output port index in_po...
python
def _pull_out_perm_lhs(lhs, rest, out_port, in_port): """Pull out a permutation from the Feedback of a SeriesProduct with itself. Args: lhs (CPermutation): The permutation circuit rest (tuple): The other SeriesProduct operands out_port (int): The feedback output port index in_po...
[ "def", "_pull_out_perm_lhs", "(", "lhs", ",", "rest", ",", "out_port", ",", "in_port", ")", ":", "out_inv", ",", "lhs_red", "=", "lhs", ".", "_factor_lhs", "(", "out_port", ")", "return", "lhs_red", "<<", "Feedback", ".", "create", "(", "SeriesProduct", "....
Pull out a permutation from the Feedback of a SeriesProduct with itself. Args: lhs (CPermutation): The permutation circuit rest (tuple): The other SeriesProduct operands out_port (int): The feedback output port index in_port (int): The feedback input port index Returns: ...
[ "Pull", "out", "a", "permutation", "from", "the", "Feedback", "of", "a", "SeriesProduct", "with", "itself", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L911-L925
train
62,888
mabuchilab/QNET
src/qnet/algebra/_rules.py
_pull_out_unaffected_blocks_lhs
def _pull_out_unaffected_blocks_lhs(lhs, rest, out_port, in_port): """In a self-Feedback of a series product, where the left-most operand is reducible, pull all non-trivial blocks outside of the feedback. Args: lhs (Circuit): The reducible circuit rest (tuple): The other SeriesProduct operands...
python
def _pull_out_unaffected_blocks_lhs(lhs, rest, out_port, in_port): """In a self-Feedback of a series product, where the left-most operand is reducible, pull all non-trivial blocks outside of the feedback. Args: lhs (Circuit): The reducible circuit rest (tuple): The other SeriesProduct operands...
[ "def", "_pull_out_unaffected_blocks_lhs", "(", "lhs", ",", "rest", ",", "out_port", ",", "in_port", ")", ":", "_", ",", "block_index", "=", "lhs", ".", "index_in_block", "(", "out_port", ")", "bs", "=", "lhs", ".", "block_structure", "nbefore", ",", "nblock"...
In a self-Feedback of a series product, where the left-most operand is reducible, pull all non-trivial blocks outside of the feedback. Args: lhs (Circuit): The reducible circuit rest (tuple): The other SeriesProduct operands out_port (int): The feedback output port index in_port (int...
[ "In", "a", "self", "-", "Feedback", "of", "a", "series", "product", "where", "the", "left", "-", "most", "operand", "is", "reducible", "pull", "all", "non", "-", "trivial", "blocks", "outside", "of", "the", "feedback", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L928-L962
train
62,889
mabuchilab/QNET
src/qnet/algebra/_rules.py
_series_feedback
def _series_feedback(series, out_port, in_port): """Invert a series self-feedback twice to get rid of unnecessary permutations.""" series_s = series.series_inverse().series_inverse() if series_s == series: raise CannotSimplify() return series_s.feedback(out_port=out_port, in_port=in_port)
python
def _series_feedback(series, out_port, in_port): """Invert a series self-feedback twice to get rid of unnecessary permutations.""" series_s = series.series_inverse().series_inverse() if series_s == series: raise CannotSimplify() return series_s.feedback(out_port=out_port, in_port=in_port)
[ "def", "_series_feedback", "(", "series", ",", "out_port", ",", "in_port", ")", ":", "series_s", "=", "series", ".", "series_inverse", "(", ")", ".", "series_inverse", "(", ")", "if", "series_s", "==", "series", ":", "raise", "CannotSimplify", "(", ")", "r...
Invert a series self-feedback twice to get rid of unnecessary permutations.
[ "Invert", "a", "series", "self", "-", "feedback", "twice", "to", "get", "rid", "of", "unnecessary", "permutations", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L997-L1003
train
62,890
mabuchilab/QNET
src/qnet/utils/properties_for_args.py
properties_for_args
def properties_for_args(cls, arg_names='_arg_names'): """For a class with an attribute `arg_names` containing a list of names, add a property for every name in that list. It is assumed that there is an instance attribute ``self._<arg_name>``, which is returned by the `arg_name` property. The decorator...
python
def properties_for_args(cls, arg_names='_arg_names'): """For a class with an attribute `arg_names` containing a list of names, add a property for every name in that list. It is assumed that there is an instance attribute ``self._<arg_name>``, which is returned by the `arg_name` property. The decorator...
[ "def", "properties_for_args", "(", "cls", ",", "arg_names", "=", "'_arg_names'", ")", ":", "from", "qnet", ".", "algebra", ".", "core", ".", "scalar_algebra", "import", "Scalar", "scalar_args", "=", "False", "if", "hasattr", "(", "cls", ",", "'_scalar_args'", ...
For a class with an attribute `arg_names` containing a list of names, add a property for every name in that list. It is assumed that there is an instance attribute ``self._<arg_name>``, which is returned by the `arg_name` property. The decorator also adds a class attribute :attr:`_has_properties_for_a...
[ "For", "a", "class", "with", "an", "attribute", "arg_names", "containing", "a", "list", "of", "names", "add", "a", "property", "for", "every", "name", "in", "that", "list", "." ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/properties_for_args.py#L8-L36
train
62,891
django-fluent/django-fluent-blogs
fluent_blogs/views/entries.py
EntryCategoryArchive.get_category
def get_category(self, slug): """ Get the category object """ try: return get_category_for_slug(slug) except ObjectDoesNotExist as e: raise Http404(str(e))
python
def get_category(self, slug): """ Get the category object """ try: return get_category_for_slug(slug) except ObjectDoesNotExist as e: raise Http404(str(e))
[ "def", "get_category", "(", "self", ",", "slug", ")", ":", "try", ":", "return", "get_category_for_slug", "(", "slug", ")", "except", "ObjectDoesNotExist", "as", "e", ":", "raise", "Http404", "(", "str", "(", "e", ")", ")" ]
Get the category object
[ "Get", "the", "category", "object" ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/views/entries.py#L190-L197
train
62,892
django-fluent/django-fluent-blogs
fluent_blogs/admin/forms.py
AbstractEntryBaseAdminForm.validate_unique_slug
def validate_unique_slug(self, cleaned_data): """ Test whether the slug is unique within a given time period. """ date_kwargs = {} error_msg = _("The slug is not unique") # The /year/month/slug/ URL determines when a slug can be unique. pubdate = cleaned_data['pu...
python
def validate_unique_slug(self, cleaned_data): """ Test whether the slug is unique within a given time period. """ date_kwargs = {} error_msg = _("The slug is not unique") # The /year/month/slug/ URL determines when a slug can be unique. pubdate = cleaned_data['pu...
[ "def", "validate_unique_slug", "(", "self", ",", "cleaned_data", ")", ":", "date_kwargs", "=", "{", "}", "error_msg", "=", "_", "(", "\"The slug is not unique\"", ")", "# The /year/month/slug/ URL determines when a slug can be unique.", "pubdate", "=", "cleaned_data", "["...
Test whether the slug is unique within a given time period.
[ "Test", "whether", "the", "slug", "is", "unique", "within", "a", "given", "time", "period", "." ]
86b148549a010eaca9a2ea987fe43be250e06c50
https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/admin/forms.py#L50-L84
train
62,893
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
_apply_rules_no_recurse
def _apply_rules_no_recurse(expr, rules): """Non-recursively match expr again all rules""" try: # `rules` is an OrderedDict key => (pattern, replacement) items = rules.items() except AttributeError: # `rules` is a list of (pattern, replacement) tuples items = enumerate(rules)...
python
def _apply_rules_no_recurse(expr, rules): """Non-recursively match expr again all rules""" try: # `rules` is an OrderedDict key => (pattern, replacement) items = rules.items() except AttributeError: # `rules` is a list of (pattern, replacement) tuples items = enumerate(rules)...
[ "def", "_apply_rules_no_recurse", "(", "expr", ",", "rules", ")", ":", "try", ":", "# `rules` is an OrderedDict key => (pattern, replacement)", "items", "=", "rules", ".", "items", "(", ")", "except", "AttributeError", ":", "# `rules` is a list of (pattern, replacement) tup...
Non-recursively match expr again all rules
[ "Non", "-", "recursively", "match", "expr", "again", "all", "rules" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L694-L709
train
62,894
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
Expression.create
def create(cls, *args, **kwargs): """Instantiate while applying automatic simplifications Instead of directly instantiating `cls`, it is recommended to use :meth:`create`, which applies simplifications to the args and keyword arguments according to the :attr:`simplifications` class attr...
python
def create(cls, *args, **kwargs): """Instantiate while applying automatic simplifications Instead of directly instantiating `cls`, it is recommended to use :meth:`create`, which applies simplifications to the args and keyword arguments according to the :attr:`simplifications` class attr...
[ "def", "create", "(", "cls", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "global", "LEVEL", "if", "LOG", ":", "logger", "=", "logging", ".", "getLogger", "(", "'QNET.create'", ")", "logger", ".", "debug", "(", "\"%s%s.create(*args, **kwargs); args...
Instantiate while applying automatic simplifications Instead of directly instantiating `cls`, it is recommended to use :meth:`create`, which applies simplifications to the args and keyword arguments according to the :attr:`simplifications` class attribute, and returns an appropriate obj...
[ "Instantiate", "while", "applying", "automatic", "simplifications" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L104-L186
train
62,895
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
Expression.kwargs
def kwargs(self): """The dictionary of keyword-only arguments for the instantiation of the Expression""" # Subclasses must override this property if and only if they define # keyword-only arguments in their __init__ method if hasattr(self, '_has_kwargs') and self._has_kwargs: ...
python
def kwargs(self): """The dictionary of keyword-only arguments for the instantiation of the Expression""" # Subclasses must override this property if and only if they define # keyword-only arguments in their __init__ method if hasattr(self, '_has_kwargs') and self._has_kwargs: ...
[ "def", "kwargs", "(", "self", ")", ":", "# Subclasses must override this property if and only if they define", "# keyword-only arguments in their __init__ method", "if", "hasattr", "(", "self", ",", "'_has_kwargs'", ")", "and", "self", ".", "_has_kwargs", ":", "raise", "Not...
The dictionary of keyword-only arguments for the instantiation of the Expression
[ "The", "dictionary", "of", "keyword", "-", "only", "arguments", "for", "the", "instantiation", "of", "the", "Expression" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L346-L355
train
62,896
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
Expression.substitute
def substitute(self, var_map): """Substitute sub-expressions Args: var_map (dict): Dictionary with entries of the form ``{expr: substitution}`` """ if self in var_map: return var_map[self] return self._substitute(var_map)
python
def substitute(self, var_map): """Substitute sub-expressions Args: var_map (dict): Dictionary with entries of the form ``{expr: substitution}`` """ if self in var_map: return var_map[self] return self._substitute(var_map)
[ "def", "substitute", "(", "self", ",", "var_map", ")", ":", "if", "self", "in", "var_map", ":", "return", "var_map", "[", "self", "]", "return", "self", ".", "_substitute", "(", "var_map", ")" ]
Substitute sub-expressions Args: var_map (dict): Dictionary with entries of the form ``{expr: substitution}``
[ "Substitute", "sub", "-", "expressions" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L387-L396
train
62,897
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
Expression.apply_rules
def apply_rules(self, rules, recursive=True): """Rebuild the expression while applying a list of rules The rules are applied against the instantiated expression, and any sub-expressions if `recursive` is True. Rule application is best though of as a pattern-based substitution. This is d...
python
def apply_rules(self, rules, recursive=True): """Rebuild the expression while applying a list of rules The rules are applied against the instantiated expression, and any sub-expressions if `recursive` is True. Rule application is best though of as a pattern-based substitution. This is d...
[ "def", "apply_rules", "(", "self", ",", "rules", ",", "recursive", "=", "True", ")", ":", "if", "recursive", ":", "new_args", "=", "[", "_apply_rules", "(", "arg", ",", "rules", ")", "for", "arg", "in", "self", ".", "args", "]", "new_kwargs", "=", "{...
Rebuild the expression while applying a list of rules The rules are applied against the instantiated expression, and any sub-expressions if `recursive` is True. Rule application is best though of as a pattern-based substitution. This is different from the *automatic* rules that :meth:`c...
[ "Rebuild", "the", "expression", "while", "applying", "a", "list", "of", "rules" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L532-L563
train
62,898
mabuchilab/QNET
src/qnet/algebra/core/abstract_algebra.py
Expression.apply_rule
def apply_rule(self, pattern, replacement, recursive=True): """Apply a single rules to the expression This is equivalent to :meth:`apply_rules` with ``rules=[(pattern, replacement)]`` Args: pattern (.Pattern): A pattern containing one or more wildcards replaceme...
python
def apply_rule(self, pattern, replacement, recursive=True): """Apply a single rules to the expression This is equivalent to :meth:`apply_rules` with ``rules=[(pattern, replacement)]`` Args: pattern (.Pattern): A pattern containing one or more wildcards replaceme...
[ "def", "apply_rule", "(", "self", ",", "pattern", ",", "replacement", ",", "recursive", "=", "True", ")", ":", "return", "self", ".", "apply_rules", "(", "[", "(", "pattern", ",", "replacement", ")", "]", ",", "recursive", "=", "recursive", ")" ]
Apply a single rules to the expression This is equivalent to :meth:`apply_rules` with ``rules=[(pattern, replacement)]`` Args: pattern (.Pattern): A pattern containing one or more wildcards replacement (callable): A callable that takes the wildcard names in ...
[ "Apply", "a", "single", "rules", "to", "the", "expression" ]
cc20d26dad78691d34c67173e5cd67dcac94208a
https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L565-L600
train
62,899