Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Parameter Namespaces [Variant B] #418

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

lumip
Copy link
Contributor

@lumip lumip commented Nov 28, 2018

Functionality to put parameters in namespaces, alternative to #400
added specialized classes NamespacedSymbol, NamespacedIndexedBase and SymbolNamespace. Adapated routines to identify subscripted symbols. Allows symbol names with explicit namespacing, e.g. "NS(foo).bar", "NS(foo).NS(bar).bar" to signalize namespaces for parameters. These symbols will be represented by the classes above.

compared to Variant A, this is a more explicit namespace notation with two advantages:

  • no internal renaming of namespaced parameters -> nicer/less confusing debugging (renaming still takes place in evaluate_lamdified but nobody ever sees that)
  • due to separate SymbolNamespace class, no conflict with accesses to symbol attributes

todo:

  • ensure that namespaced parameters work with all PulseTempaltes (TablePT and MappingPT done)

note:
branch issues/344_parameter_namespaces_3_attempt_at_no_renaming_for_lamdified_val is an attempt to forego flattening of nested parameter dictionaries by printing lamdified code that directly works on nested dicts. however, it currently does not work

when merged, closes #344

…he allow_partial_parameter_mapping argument.

parameters which are not mapped by the parameter_mapping dict passed to MappingPT are automatically mapped using identity mapping.
Added mapping_namespace argument to MappingPT. All parameters of the inner template not explicitely mapped by the parameter_mapping provided to MappingPT are placed into the provided namespace by mapping them to parameters named <mapping_namespace>___<original name>. If the parameter already was in a namespace (i.e. had a prefix ending with ___) this is replaced by the new namespace/prefix.
…pressions.

Created customized version of the auto_symbol token transformation used by sympy.parse_expr and mocked that into sympy when calling sympify and co.
Works well for sympify but not at all for lambdified and compiled expressions.
An issue for lamdified expression is that the namespaced parameters will become kwargs and python cannot deal with the dot in there.
anything to be done? WIP? probably just scrap this..
Removed custom parsing routines. Enhanced functionality of IndexedBaseFinder to also find namespaces.
Introduced NamespaceSymbol.
Currently still somewhat messy, will be cleaned up in the following.
…ons now accepts numpy arrays of expressions as arguments as well.
@coveralls
Copy link

coveralls commented Nov 28, 2018

Pull Request Test Coverage Report for Build 1769

  • 245 of 282 (86.88%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 93.038%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qupulse/expressions.py 12 13 92.31%
qupulse/pulses/mapping_pulse_template.py 20 21 95.24%
qupulse/utils/sympy.py 211 246 85.77%
Totals Coverage Status
Change from base Build 1763: -0.4%
Covered Lines: 4999
Relevant Lines: 5300

💛 - Coveralls

…mespaces for parameters not explicitly mapped.

- removed mapping_namespace argument which is now obsolete
- also added subs_namespace method to Expression(Scalar)
which return the SymbolNamespace objects or the respective namespace names of all root level, i.e., not nested, namespaces
which is used by get_root_namespaces and was missing in a previous commit.
…paces in evaluate methods

- added method flatten_parameter_dict which transforms nested dicts into flat dicts with keys following namespace syntax
- PulseTemplate transforms nested parameters dicts into flat ones
- test that TablePT can handle namespaced parameters names in build_waveform (given a flat parameter dict)
@lumip lumip changed the title [DO NOT MERGE] Parameter Namespaces [Variant B] [WIP] Parameter Namespaces [Variant B] Dec 11, 2018
# Conflicts:
#	qupulse/pulses/mapping_pulse_template.py
#	qupulse/pulses/pulse_template.py
#	tests/pulses/mapping_pulse_template_tests.py
#	tests/utils/sympy_tests.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce Namespaces for Parameters
3 participants