Skip to content

Conversation

@antalszava
Copy link
Contributor

@antalszava antalszava commented May 28, 2025

Description

This PR updates the plotting functionality that's on a feature branch such that it can handle redundancies in the naming.

It renders well the relevant cases discussed in #188.

Please verify that you have completed the following steps

  • I have self-reviewed my code.
  • I have included test cases validating introduced feature/fix.
  • I have updated documentation. N/A: no documentation yet for this feature.

@antalszava antalszava changed the title Further improve visualisations feat: added treemap visualisation class Jun 9, 2025
@antalszava
Copy link
Contributor Author

Hi @Brendan-Reid1991, I've updated the PR as per the comments. Thank you for the feedback!

Note some changes in logic to iron things out:

  • TreeMap may accept Routine too - in such cases, such a routine is compiled so that the TreeMap can operate on a compiled routine - the main reason for this is that it eased the validation check of numeric routines (see more details in the next point);
  • The check to see if a routine is numeric seemed to have gone down a rabbit hole of its sort: for simple Routine objects, the resources attribute is empty; hence I defaulted to only validation checking compiled routines.

Then, my findings were the following. If the input resource value

  • Was a string, then the corresponding resource value type of the compiled routine was a sympy.Symbol whose string value was the original input string;
  • Was a float or int, then it remained a float or int;
  • Was not defined, then it may be defined by bartiq under the hood by inference from the resource values of the (potential) children of the said routine - in such a case the type of this object was either a sympy.Symbol with the distinct pattern of child_name.resource_name or a more involved sympy Expr object created as a mixture of the resource values of multiple children.

Assuming that input resource values to a routine are either only string, float or int, checking that a routine is numeric seems to boil down to checking that all the resource values of the compiled routine (and its potential children, grandchildren, etc.) exhibit the child_name.resource_name pattern if their type is sympy.Symbol or are otherwise a Number or sympy.Expr. So, such a validation was added to define CompiledRoutine.is_numeric.

I've also added the requested test cases.

Let me know how the changes look in this form. 👍

@Brendan-Reid1991
Copy link
Contributor

@antalszava Thank you! This looks great.

The one thing I'm unsure about is the new methods on Routine objects. Since a Routine object is distinct from a CompiledRoutine, I'm not sure it is kosher to accept Routine and then compile it behind the scenes. Since a tree map is a) nested and b) numeric by design, accepting:

  • a numeric, uncompiled routine violates a), since the proper relationships and have not been determined (and it is not the job of the tree map class to compile!)
  • a symbolic, uncompiled routine violates a) and b), and a treemap of symbolic equations would be nigh impossible to represent cleanly.
  • a symbolic compiled routine violates b), and we use the same reasoning as above
  • a numeric compiled routine doesn't violate either of these, and should be the only acceptable input.

Furthermore, while I appreciate the forethought of testing all the children and grandchildren for numerics, it is unnecessary if the input to TreeMap is type hinted as only a CompiledRoutine. The compilation procedure in bartiq ensures that that nth level inherits from the (n+1)th level, where 0th is the root, 1st is the first layer of children etc. So, a CompiledRoutine object with numeric top level resources and symbolic lower level resources should not be possible. I know this to be true, but whether or not we have thought of all possible "unintended ways of using bartiq" and tried to catch them, I can't say**. But this would not be the job of TreeMap to catch.

By only accepting numeric, CompiledRoutines, we also avoid the issue of the child_name.resource_name format of the unevaluated resource values. Essentially, the user has to evaluate their routine to be accepted by TreeMap. It will be enough to type hint for CompiledRoutine, and then do a check on the top level resources to ensure they are all Number types. You've done more work than you needed to! But I appreciate it.

I can merge this today, with the following changes:

  • Remove new methods from _routine.py
  • Change type hinting for TreeMap to only accept CompiledRoutines, and check for all numeric top level resources.
  • Move from if resource not in self.valid_resources check from plot into get_dataframe, as get_dataframe is also public, and plot calls get_dataframe. So it only needs to exist in get_dataframe!
  • Line 127 in visualizations.py should be changed from "Contribution" -> contribution to avoid string duplication.

Thank you again!

**NB: We did not intend Routine/CompiledRoutine objects to be manually created, so there may be a way to strong-arm it. This falls under "unintended ways of using bartiq" though.

@Brendan-Reid1991
Copy link
Contributor

And isort failed! Looks like some command modified the import layout, could be a default formatter issue. isort --profile=black . will fix it.

@antalszava
Copy link
Contributor Author

Hi @Brendan-Reid1991, sure, thank you for the guidance. 👍

By only accepting numeric, CompiledRoutines, we also avoid the issue of the child_name.resource_name format of the unevaluated resource values. Essentially, the user has to evaluate their routine to be accepted by TreeMap. It will be enough to type hint for CompiledRoutine, and then do a check on the top level resources to ensure they are all Number types. You've done more work than you needed to! But I appreciate it.

The reason for the complex logic I've implemented before was that when creating a routine by hand, I could create one where I don't specify the resource of the top-level routine, but only those of the children and then the top-level resource value is symbolic, and the low level ones can still be numeric.

E.g.,

from qref import SchemaV1

from bartiq import Routine, compile_routine
from bartiq.symbolics.sympy_backend import SympyBackend
from bartiq.visualizations import TreeMap, _dataframe_with_unique_routine_names

input_schema = SchemaV1(
    program={
        "name": "root",
        "children": [
            {
                "name": "child1",
                "children": [
                    {
                        "name": "child3",
                        "resources": [
                            {"name": "success_rate", "type": "multiplicative", "value": 7260.0},
                        ],
                    },
                ],
                "resources": [
                    {"name": "success_rate", "type": "multiplicative", "value": 3630.0},
                ],
            },
            {
                "name": "child2",
                "resources": [
                    {"name": "success_rate", "type": "multiplicative", "value": 2320.0},
                ],
            },
        ],
    },
    version="v1",
)

backend = SympyBackend()
routine_from_qref = Routine.from_qref(input_schema, backend=backend)
c_routine = compile_routine(routine_from_qref).routine
type(c_routine.resources['success_rate'].value)

gives

sympy.core.mul.Mul

I intended to check for such cases too - based on the explanation, my understanding now is that likely that's not something bartiq would produce.

I've carried out the changes mentioned. Thank you for the pointers.

And isort failed! Looks like some command modified the import layout, could be a default formatter issue. isort --profile=black . will fix it.

My bad! Had a higher version of isort locally which made the changes - now should be good.

@Brendan-Reid1991
Copy link
Contributor

Amazing @antalszava ! I've approved there now, once the pipeline passes I'll ping Michal to merge and make sure you get your bounty :)

@Brendan-Reid1991 Brendan-Reid1991 merged commit 3bd44aa into PsiQ:main Jun 9, 2025
8 checks passed
Brendan-Reid1991 added a commit that referenced this pull request Jun 12, 2025
* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>
Brendan-Reid1991 added a commit that referenced this pull request Jun 23, 2025
…lass (#205)

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* refactor: Added CompilationFlags to init

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* refactor: Changed assertions into Exceptions

* bugfix: Changed None -> CompilationsFlags(0)

* chore: Updated compilation to discuss transitivity and compilation flags

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* feat: Began work on sympy manipulator

* feat: added instruction types enum; adding functionality to SM

* refactor: split base class + sympyManipulator into separate modules

* chore: removed generic types

* refactor: Moved InstructionsType enum

* feat: Added `focus` method. Generic types added

* refactor: Renamed SympyManipulation -> SympyManipulator

* fix: removed testing code

* refactor: renamed analysis.py -> optimization.py

* refactor: created analysis module

* feat: created rewriters module

* feat: added expressionwriter abc

* feat: subclassed from expressionwriter

* chore: improving typing

* feat: Added basic tests for rewriters

* chore: improved typing, added docstrings

* feat: improved typing; added docstrings

* chore: ran isort

* chore: fixed typing issues

* chore: added module level docstrings

* chore: removed unused import

* chore: erroneous line introduced

* chore: added module level docstring

* chore: improved typing in update_expression

* chore: added module level docstring; removed return section of docstring and improved descriptions

* chore: Type -> type

* chore: made expression_rewriter.py public

* refactor: renamed variables -> free_symbols

* refactor: improved docstrings

* chore: correcting imports

* refactor: renamed test_variables, and improved it such that it will work for all backends

* chore: added copyright message

* refactor: renamed free_symbols_in -> free_symbols

* chore: updated docstrings

* chore: isort fix

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: resolving conflicts

* chore: free_symbols_in -> free_symbols

* chore: free_symbols_in -> free_symbols

* Resolving conflicts

* began typing fixes

* Removed expression getter/setter. Updated typing

* Removed commented out code

* feat: added treemap visualisation class (#216)

* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* Removed reference to ._expr

* improved typing

* Modifying Basic -> Expr as generic type.

* Modified fixture

* improved typing

* Moved expand test to be sympy specific

* changed fixture scope from 'class' to 'function'

* renamed as_individual_terms - > individual_terms

* Renamed property; ran isort

* renamed as_individual_terms -> individual_terms

* typo fix

* Removed fixtures from tests and restructured them

* chore: update poetry.lock file for dependabot (#227)

* chore: update poetry.lock file for dependabot

* chore: update lock file

* chore: remove h11 as transient dependency

* chore: update poetry lock

* refactor: made pandas and plotly optional installs (#226)

* refactor: made pandas and plotly optional installs

* Added checks to ensure tests do not fail unexpectedly

* ran isort

* Added .venv to .gitignore

* Addition of pandas stubs changed behaviour of scipy stubs; quick fix

* renamed visualization->interactive

* updated extras flag

* renamed vis->viz

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* added plotly-stubs; may revert

* Removed type: ignore

* removed type: ignore; updated error message

* fixing plotly-stubs install

* Removed plotly-stubs entirely.

* added pytest.importorskip to module

* Added noqa to pass flake8

* Ran isort

* isort versioning mismatch

* Streamlined some aspects of the TreeMap class; removed unnecessary checks

* Removing unused imports

* fix: Fix typing in analysis module

---------

Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>

* updated substitute function to account for symbols with assumptions on them

* attempting to consolidate the typing

* Added sequence of commands as a test

* removing unused import

* Updating typing

* Implementing Konrads changes

* remove trailing whitespace

* added return statement

* minor changes to typing

* removing sequence of commands test

* fixing linting; temporary fix

---------

Co-authored-by: Avin Divakara <67309607+AVDiv@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>
Brendan-Reid1991 added a commit that referenced this pull request Jun 30, 2025
* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* refactor: Added CompilationFlags to init

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* refactor: Changed assertions into Exceptions

* bugfix: Changed None -> CompilationsFlags(0)

* chore: Updated compilation to discuss transitivity and compilation flags

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* feat: Began work on sympy manipulator

* feat: added instruction types enum; adding functionality to SM

* refactor: split base class + sympyManipulator into separate modules

* chore: removed generic types

* refactor: Moved InstructionsType enum

* feat: Added `focus` method. Generic types added

* refactor: Renamed SympyManipulation -> SympyManipulator

* fix: removed testing code

* refactor: renamed analysis.py -> optimization.py

* refactor: created analysis module

* feat: created rewriters module

* feat: added expressionwriter abc

* feat: subclassed from expressionwriter

* chore: improving typing

* feat: Added basic tests for rewriters

* chore: improved typing, added docstrings

* feat: improved typing; added docstrings

* chore: ran isort

* chore: fixed typing issues

* chore: added module level docstrings

* chore: removed unused import

* chore: erroneous line introduced

* chore: added module level docstring

* chore: improved typing in update_expression

* chore: added module level docstring; removed return section of docstring and improved descriptions

* chore: Type -> type

* chore: made expression_rewriter.py public

* refactor: renamed variables -> free_symbols

* refactor: improved docstrings

* chore: correcting imports

* refactor: renamed test_variables, and improved it such that it will work for all backends

* chore: added copyright message

* refactor: renamed free_symbols_in -> free_symbols

* chore: updated docstrings

* chore: isort fix

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* feat: began development on assumptions

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: resolving conflicts

* chore: free_symbols_in -> free_symbols

* chore: free_symbols_in -> free_symbols

* Resolving conflicts

* Improving assumptions handling

* began typing fixes

* Removed expression getter/setter. Updated typing

* Removed commented out code

* feat: added treemap visualisation class (#216)

* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* Removed reference to ._expr

* improved typing

* Modifying Basic -> Expr as generic type.

* Modified fixture

* improved typing

* Moved expand test to be sympy specific

* changed fixture scope from 'class' to 'function'

* renamed as_individual_terms - > individual_terms

* Renamed property; ran isort

* renamed as_individual_terms -> individual_terms

* typo fix

* Removed fixtures from tests and restructured them

* chore: update poetry.lock file for dependabot (#227)

* chore: update poetry.lock file for dependabot

* chore: update lock file

* chore: remove h11 as transient dependency

* chore: update poetry lock

* refactor: made pandas and plotly optional installs (#226)

* refactor: made pandas and plotly optional installs

* Added checks to ensure tests do not fail unexpectedly

* ran isort

* Added .venv to .gitignore

* Addition of pandas stubs changed behaviour of scipy stubs; quick fix

* renamed visualization->interactive

* updated extras flag

* renamed vis->viz

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* added plotly-stubs; may revert

* Removed type: ignore

* removed type: ignore; updated error message

* fixing plotly-stubs install

* Removed plotly-stubs entirely.

* added pytest.importorskip to module

* Added noqa to pass flake8

* Ran isort

* isort versioning mismatch

* Streamlined some aspects of the TreeMap class; removed unnecessary checks

* Removing unused imports

* fix: Fix typing in analysis module

---------

Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>

* updated substitute function to account for symbols with assumptions on them

* attempting to consolidate the typing

* Added sequence of commands as a test

* removing unused import

* Updating typing

* Implementing Konrads changes

* remove trailing whitespace

* added return statement

* reimplementing lost changes

* Implementing SympyAssumption

* made it so child classes of ExpressionRewriters do not need the decorator

* moved evaluation check into Assumptions _post_init_

* started assumptions tracking

* quick fix for custom max problem

* improved docstrings and added comments

* added reapply_all_assumptions

* formatting

* improving properties dict

* isort

* formatting

* began tests

* updated properties dict

* added tests

* formatting

* added comment on _add_assumption

* deleted test file

* fixing mypy issues

* fixing mypy issues

* fixing import for py3.10

* isort

* minor typo fix

* added hash to assumptions

* added decorator to override custom max

* minor refactor after removing custom max

* began improving tests

* added classmethod to sympy_backend

* added classmethod to sympy_backend

* added tests for .with_sympy_max

* rename Relationals -> Comparators

* rename relationship->comparator

* minor typo fix

* re-adding assumptions after mistaken deletion

* changed from using float to literal_eval

* added more tests for assumptions

* minor fixes

* improved typehinting

* improved tracking of assumptions

* improved tracking of assumptions

* streamlined dataclass interactions

* deleting test file

* bug fixes

* change from all caps to snake case

* moving some assumptions tests into basic tests

* fixing docstring inconsistencies

* quick fixes from michals review

* Removed classmethod; moved logic to `parse_to_sympy`

* modified interpreter to override certain functions

* modified rewriter backend def

* removed test until we settle on impl

* bug fixes, test fixes

* deleted unwanted file

* mypy fix

* added function_overrides to sympyinterpreter

* updated sympybackend with new properties

* updated rewriter after changes to sympy backend

* modified backend after changes to interpreter

* removing unnecessary kwargs

* improved docstrings

* added tests for sympy_backend when using sympy max

* rename assume->assumption

* fix typing error

* test renaming

* renaming assumption->assume

* typo

* another typo

* renamed kwarg to assumption

---------

Co-authored-by: Avin Divakara <67309607+AVDiv@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>
Brendan-Reid1991 added a commit that referenced this pull request Jul 2, 2025
…ory tracking (#237)

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* refactor: Added CompilationFlags to init

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* refactor: Changed assertions into Exceptions

* bugfix: Changed None -> CompilationsFlags(0)

* chore: Updated compilation to discuss transitivity and compilation flags

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* feat: Began work on sympy manipulator

* feat: added instruction types enum; adding functionality to SM

* refactor: split base class + sympyManipulator into separate modules

* chore: removed generic types

* refactor: Moved InstructionsType enum

* feat: Added `focus` method. Generic types added

* refactor: Renamed SympyManipulation -> SympyManipulator

* fix: removed testing code

* refactor: renamed analysis.py -> optimization.py

* refactor: created analysis module

* feat: created rewriters module

* feat: added expressionwriter abc

* feat: subclassed from expressionwriter

* chore: improving typing

* feat: Added basic tests for rewriters

* chore: improved typing, added docstrings

* feat: improved typing; added docstrings

* chore: ran isort

* chore: fixed typing issues

* chore: added module level docstrings

* chore: removed unused import

* chore: erroneous line introduced

* chore: added module level docstring

* chore: improved typing in update_expression

* chore: added module level docstring; removed return section of docstring and improved descriptions

* chore: Type -> type

* chore: made expression_rewriter.py public

* refactor: renamed variables -> free_symbols

* refactor: improved docstrings

* chore: correcting imports

* refactor: renamed test_variables, and improved it such that it will work for all backends

* chore: added copyright message

* refactor: renamed free_symbols_in -> free_symbols

* chore: updated docstrings

* chore: isort fix

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* feat: began development on assumptions

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: resolving conflicts

* chore: free_symbols_in -> free_symbols

* chore: free_symbols_in -> free_symbols

* Resolving conflicts

* Improving assumptions handling

* began typing fixes

* Removed expression getter/setter. Updated typing

* Removed commented out code

* feat: added treemap visualisation class (#216)

* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* Removed reference to ._expr

* improved typing

* Modifying Basic -> Expr as generic type.

* Modified fixture

* improved typing

* Moved expand test to be sympy specific

* changed fixture scope from 'class' to 'function'

* renamed as_individual_terms - > individual_terms

* Renamed property; ran isort

* renamed as_individual_terms -> individual_terms

* typo fix

* Removed fixtures from tests and restructured them

* chore: update poetry.lock file for dependabot (#227)

* chore: update poetry.lock file for dependabot

* chore: update lock file

* chore: remove h11 as transient dependency

* chore: update poetry lock

* refactor: made pandas and plotly optional installs (#226)

* refactor: made pandas and plotly optional installs

* Added checks to ensure tests do not fail unexpectedly

* ran isort

* Added .venv to .gitignore

* Addition of pandas stubs changed behaviour of scipy stubs; quick fix

* renamed visualization->interactive

* updated extras flag

* renamed vis->viz

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* added plotly-stubs; may revert

* Removed type: ignore

* removed type: ignore; updated error message

* fixing plotly-stubs install

* Removed plotly-stubs entirely.

* added pytest.importorskip to module

* Added noqa to pass flake8

* Ran isort

* isort versioning mismatch

* Streamlined some aspects of the TreeMap class; removed unnecessary checks

* Removing unused imports

* fix: Fix typing in analysis module

---------

Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>

* updated substitute function to account for symbols with assumptions on them

* attempting to consolidate the typing

* Added sequence of commands as a test

* removing unused import

* Updating typing

* Implementing Konrads changes

* remove trailing whitespace

* added return statement

* reimplementing lost changes

* Implementing SympyAssumption

* made it so child classes of ExpressionRewriters do not need the decorator

* moved evaluation check into Assumptions _post_init_

* started assumptions tracking

* quick fix for custom max problem

* improved docstrings and added comments

* added reapply_all_assumptions

* formatting

* improving properties dict

* isort

* formatting

* began tests

* updated properties dict

* added tests

* formatting

* added comment on _add_assumption

* deleted test file

* fixing mypy issues

* fixing mypy issues

* fixing import for py3.10

* isort

* minor typo fix

* Added substitution methods

* implemented sympy substitutions,including wildcards

* modified substitute to allow arbitrary substitutions"

* improvements to wildcard subs

* fixed final bug in wildcard subs

* added hash to assumptions

* minor refactor

* added decorator to override custom max

* minor refactor after removing custom max

* began improving tests

* added classmethod to sympy_backend

* added classmethod to sympy_backend

* added tests for .with_sympy_max

* rename Relationals -> Comparators

* rename relationship->comparator

* minor typo fix

* re-adding assumptions after mistaken deletion

* changed from using float to literal_eval

* added more tests for assumptions

* minor fixes

* mypy fixes

* docstring updates;mypy fixes;wildcard improvements

* mypy fixes

* improved typehinting

* improved tracking of assumptions

* improved tracking of assumptions

* updating evaluate from main

* minor fixes

* gave _substitute default behaviour

* streamlined dataclass interactions

* deleting test file

* added_named_tuple

* bug fixes

* change from all caps to snake case

* minor refactor

* started testing substitutions

* moving some assumptions tests into basic tests

* updated focus + substitution logic

* added tests

* fixing docstring inconsistencies

* quick fixes from michals review

* Removed classmethod; moved logic to `parse_to_sympy`

* modified interpreter to override certain functions

* modified rewriter backend def

* removed test until we settle on impl

* bug fixes, test fixes

* deleted unwanted file

* mypy fix

* minor change

* refactor

* added function_overrides to sympyinterpreter

* updated sympybackend with new properties

* updated rewriter after changes to sympy backend

* modified backend after changes to interpreter

* removing unnecessary kwargs

* improved docstrings

* added tests for sympy_backend when using sympy max

* rename assume->assumption

* fix typing error

* test renaming

* refactored into dataclasses

* removing tests from downstream branch

* added instruction set

* renaming assumption->assume

* typo

* another typo

* renamed kwarg to assumption

* fixing typing & usability

* updated tests to pass

* fixing imports

* deleted erroneous line

* added tests for history tracking

* deleted duplicate fn

* removed revert_to in favour of undo_previous; renamed show_history; improved docstrings

* fixed implementation error in reapply_all_assumptions

* fixed implementation error in focus

* added original; hardcoded sympy backend to prevent reinstantiation

* modified history methods; updated tests

* reverting change to sympy_backend

---------

Co-authored-by: Avin Divakara <67309607+AVDiv@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>
Brendan-Reid1991 added a commit that referenced this pull request Jul 10, 2025
* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* feat: Began work on sympy manipulator

* feat: added instruction types enum; adding functionality to SM

* refactor: split base class + sympyManipulator into separate modules

* chore: removed generic types

* refactor: Moved InstructionsType enum

* feat: Added `focus` method. Generic types added

* refactor: Renamed SympyManipulation -> SympyManipulator

* fix: removed testing code

* refactor: renamed analysis.py -> optimization.py

* refactor: created analysis module

* feat: created rewriters module

* feat: added expressionwriter abc

* feat: subclassed from expressionwriter

* chore: improving typing

* feat: Added basic tests for rewriters

* chore: improved typing, added docstrings

* feat: improved typing; added docstrings

* chore: ran isort

* chore: fixed typing issues

* chore: added module level docstrings

* chore: removed unused import

* chore: erroneous line introduced

* chore: added module level docstring

* chore: improved typing in update_expression

* chore: added module level docstring; removed return section of docstring and improved descriptions

* chore: Type -> type

* chore: made expression_rewriter.py public

* refactor: renamed variables -> free_symbols

* refactor: improved docstrings

* chore: correcting imports

* refactor: renamed test_variables, and improved it such that it will work for all backends

* chore: added copyright message

* refactor: renamed free_symbols_in -> free_symbols

* chore: updated docstrings

* chore: isort fix

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* feat: began development on assumptions

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: resolving conflicts

* chore: free_symbols_in -> free_symbols

* chore: free_symbols_in -> free_symbols

* Resolving conflicts

* Improving assumptions handling

* began typing fixes

* Removed expression getter/setter. Updated typing

* Removed commented out code

* feat: added treemap visualisation class (#216)

* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* Removed reference to ._expr

* improved typing

* Modifying Basic -> Expr as generic type.

* Modified fixture

* improved typing

* Moved expand test to be sympy specific

* changed fixture scope from 'class' to 'function'

* renamed as_individual_terms - > individual_terms

* Renamed property; ran isort

* renamed as_individual_terms -> individual_terms

* typo fix

* Removed fixtures from tests and restructured them

* chore: update poetry.lock file for dependabot (#227)

* chore: update poetry.lock file for dependabot

* chore: update lock file

* chore: remove h11 as transient dependency

* chore: update poetry lock

* refactor: made pandas and plotly optional installs (#226)

* refactor: made pandas and plotly optional installs

* Added checks to ensure tests do not fail unexpectedly

* ran isort

* Added .venv to .gitignore

* Addition of pandas stubs changed behaviour of scipy stubs; quick fix

* renamed visualization->interactive

* updated extras flag

* renamed vis->viz

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* added plotly-stubs; may revert

* Removed type: ignore

* removed type: ignore; updated error message

* fixing plotly-stubs install

* Removed plotly-stubs entirely.

* added pytest.importorskip to module

* Added noqa to pass flake8

* Ran isort

* isort versioning mismatch

* Streamlined some aspects of the TreeMap class; removed unnecessary checks

* Removing unused imports

* fix: Fix typing in analysis module

---------

Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>

* updated substitute function to account for symbols with assumptions on them

* attempting to consolidate the typing

* Added sequence of commands as a test

* removing unused import

* Updating typing

* Implementing Konrads changes

* remove trailing whitespace

* added return statement

* reimplementing lost changes

* Implementing SympyAssumption

* made it so child classes of ExpressionRewriters do not need the decorator

* moved evaluation check into Assumptions _post_init_

* started assumptions tracking

* quick fix for custom max problem

* improved docstrings and added comments

* added reapply_all_assumptions

* formatting

* improving properties dict

* isort

* formatting

* began tests

* updated properties dict

* added tests

* formatting

* added comment on _add_assumption

* deleted test file

* fixing mypy issues

* fixing mypy issues

* fixing import for py3.10

* isort

* minor typo fix

* Added substitution methods

* implemented sympy substitutions,including wildcards

* modified substitute to allow arbitrary substitutions"

* improvements to wildcard subs

* fixed final bug in wildcard subs

* added hash to assumptions

* minor refactor

* added decorator to override custom max

* minor refactor after removing custom max

* began improving tests

* added classmethod to sympy_backend

* added classmethod to sympy_backend

* added tests for .with_sympy_max

* rename Relationals -> Comparators

* rename relationship->comparator

* minor typo fix

* re-adding assumptions after mistaken deletion

* changed from using float to literal_eval

* added more tests for assumptions

* minor fixes

* mypy fixes

* docstring updates;mypy fixes;wildcard improvements

* mypy fixes

* improved typehinting

* improved tracking of assumptions

* improved tracking of assumptions

* updating evaluate from main

* minor fixes

* gave _substitute default behaviour

* streamlined dataclass interactions

* deleting test file

* added_named_tuple

* bug fixes

* change from all caps to snake case

* minor refactor

* started testing substitutions

* moving some assumptions tests into basic tests

* updated focus + substitution logic

* added tests

* fixing docstring inconsistencies

* quick fixes from michals review

* Removed classmethod; moved logic to `parse_to_sympy`

* modified interpreter to override certain functions

* modified rewriter backend def

* removed test until we settle on impl

* bug fixes, test fixes

* deleted unwanted file

* mypy fix

* minor change

* refactor

* added function_overrides to sympyinterpreter

* updated sympybackend with new properties

* updated rewriter after changes to sympy backend

* modified backend after changes to interpreter

* removing unnecessary kwargs

* improved docstrings

* added tests for sympy_backend when using sympy max

* rename assume->assumption

* fix typing error

* test renaming

* typing fixes

* refactored into dataclasses

* removing tests from downstream branch

* added instruction set

* renaming assumption->assume

* typo

* another typo

* renamed kwarg to assumption

* fixing typing & usability

* updated tests to pass

* fixing imports

* deleted erroneous line

* added tests for history tracking

* fixing mypy issues

* refactored instructions

* refactored assumptions as child of dummy class

* modified tests after refactor

* made rewriters public

* made rewriters public

* deleting files

* exposed rewriter factory

* modified how substitutions are added

* minor refactor on substitutions; added factory  method

* improved logic on linked parameters

* updated tests after refactor

* added new ignore code to flake8

* remove unnecessary guards

* improving docstrings

* improving tests

* tighting typing

* added tests for linked parameters in focus

* added per-file ignore code for lambdas

* made wild chars stored in tuples rather than list

* removed None type from original_expression

* removed noqa

* simplified logic after Konrads comments

* minor typing typo (typ-o)

* fixing typos in docstring

* updating docstrings

* minor factor on substitutions

* updating tests

* fixing attr error

* fixing tests

* removed testig code

* updated assumption properties derivation; improved docstrings

* updated tests

* missing word in docstring

---------

Co-authored-by: Avin Divakara <67309607+AVDiv@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>
Brendan-Reid1991 added a commit that referenced this pull request Jul 14, 2025
…ines (#239)

* chore: added module level docstrings

* chore: removed unused import

* chore: erroneous line introduced

* chore: added module level docstring

* chore: improved typing in update_expression

* chore: added module level docstring; removed return section of docstring and improved descriptions

* chore: Type -> type

* chore: made expression_rewriter.py public

* refactor: renamed variables -> free_symbols

* refactor: improved docstrings

* chore: correcting imports

* refactor: renamed test_variables, and improved it such that it will work for all backends

* chore: added copyright message

* refactor: renamed free_symbols_in -> free_symbols

* chore: updated docstrings

* chore: isort fix

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* feat: began development on assumptions

* chore: Added a comment about allow_transitive_resources to tutorial #1

* chore: added allow_transitive_resources=False; added quotes to Note about interactive tools

* chore: updated tutorial 3

* chore: Added sentences about transitive compilation of resources

* refactor: Created `CompilationFlags` enum

* refactor: Replaced asserts with Exceptions; added fix for repetitions + transitive resources

* chore: Updated docstrings

* chore: updating tests for CompilationFlags

* chore: Modified tests to catch edge case errors (previously assertions)

* chore: Updated tutorials with Compilation Flags

* refactor: creating analysis submodule.

* docs: improve the API docs (#209)

* docs: Added the list of possible values for `ResourceType` and `PortDirection` on docstring

* docs: Added missing `Raises` sections in existing docstrings

* docs: Improved styling of function segments in docs for easy navigation

* docs: Added clickable reference links to parts of documentations in doc strings

* fix: Fixed the formatting and lint issues

* fix(docs): Fixed docs reference issues on`_compile.py`, `_evaluate.py` & `_routine.py`

* fix: Exposed `SymbolicBackend` through `bartiq.symbolics`

* fix: Exposed `Port` at top level (`bartiq.Port`)

* docs: Adding doc-string for `Port` class

* fix(docs): Added missing Args, and references in modified docs

* fix(docs): Added External references

* fix(docs): Fixed issues of long `Return` descriptions

* fix(docs): Reverting `symbolics` concept markdown content

* fix(docs): Improved styling of overload functions displayed in docs & removed type hints for `postorder_transform`

* fix(docs): Fixed a formatting issue in the module doc-string

* fix(docs): Removed `SymbolicBackend`  from exposing to top-level, and added submodule rendering and extra styling for documentation

* fix(docs): Removed unnecessary doc-strings in each `postorder_transform` overload function

* fix(docs): Extended `module` & `method` annotations in docs

* chore: resolving conflicts

* chore: free_symbols_in -> free_symbols

* chore: free_symbols_in -> free_symbols

* Resolving conflicts

* Improving assumptions handling

* began typing fixes

* Removed expression getter/setter. Updated typing

* Removed commented out code

* feat: added treemap visualisation class (#216)

* Added GSE prototype

* Trialling a decorator function

* Added warning if no update applied; added methods to isolate functions and their arguments

* Minor fix

* Removed userwarning due to bug

* Added catch for top level expression

* Added better support for parsing assumptions and redefining symbols

* Potential bugfix; Symbols now updated correctly

* Improved logic parsing

* bug fix

* Improved detection of nonzero Symbols

* Added warning if an expression does not change

* defaulting suppress_warnings to true; still experimental

* Updated check_expression_update to catch edge cases

* bug fix: when parsing known symbols with reference values!=0

* Undoing code removal

* Minor change for readaility

* more bug fixes

* More bug fixes

* Hopefully the last bug fix

* tbd

* tbd

* Updated imports after merge

* Minor improvements

* Added ability to evaluate gnarly

* Attempting to fix evaluation bug

* bug fix

* bug  found on substitute

* Removed unused import

* Added fix to allow substitute to refer to symbols rather than symbol names

* Removed unnecessary print statement

* Bandaid fix for minor bug

* Small fix

* fix: proper detection for zero arguments

* Upgraded grammar and text in alias-sampling

* Only minor changes to the third tutorial

* Typo fix.

* Added visualisations module; needs depth parameter.

* scratch notebook

* Pausing work; creating issue in bartiq.

* feat: visualisation improvement cleanup

* feat: visualisation improvement cleanup

* feat: create a method that can handle dataframe with redundant names

* test: test the new method

* chore: linting

* chore: include pandas and plotly in dependencies

* Update src/bartiq/visualisations.py

Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: file removal and renaming from review

* feat: added is_numeric method and visualization input validation check logic

* test: added compiled routine is_numeric tests and input validation for visualization

* chore: remove scale_to

* chore: delete changes to sympy backend

* chore: private function instead of classmethod

* chore: reset advanced example

* chore: validation checking invalid resource to plot

* chore: avoid duplication of strings when calling px.treemap

* test: output data frame is as expected

* test: test plot output type

* chore: adjust docstring and test function signatures

* chore: linting

* chore: linting

* chore: address review comments

* chore: address review comment

---------

Co-authored-by: brendan reid <brendan.reid1991@gmail.com>
Co-authored-by: Brendan Reid <breid@psiquantum.com>
Co-authored-by: Dr Brendan Reid <53276074+Brendan-Reid1991@users.noreply.github.com>

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* Removed reference to ._expr

* improved typing

* Modifying Basic -> Expr as generic type.

* Modified fixture

* improved typing

* Moved expand test to be sympy specific

* changed fixture scope from 'class' to 'function'

* renamed as_individual_terms - > individual_terms

* Renamed property; ran isort

* renamed as_individual_terms -> individual_terms

* typo fix

* Removed fixtures from tests and restructured them

* chore: update poetry.lock file for dependabot (#227)

* chore: update poetry.lock file for dependabot

* chore: update lock file

* chore: remove h11 as transient dependency

* chore: update poetry lock

* refactor: made pandas and plotly optional installs (#226)

* refactor: made pandas and plotly optional installs

* Added checks to ensure tests do not fail unexpectedly

* ran isort

* Added .venv to .gitignore

* Addition of pandas stubs changed behaviour of scipy stubs; quick fix

* renamed visualization->interactive

* updated extras flag

* renamed vis->viz

* chore: rename nlz to ntz (#225)

* chore: rename nlz to ntz

* chore: add deprecated class alias.

* fix: test and linter

* added plotly-stubs; may revert

* Removed type: ignore

* removed type: ignore; updated error message

* fixing plotly-stubs install

* Removed plotly-stubs entirely.

* added pytest.importorskip to module

* Added noqa to pass flake8

* Ran isort

* isort versioning mismatch

* Streamlined some aspects of the TreeMap class; removed unnecessary checks

* Removing unused imports

* fix: Fix typing in analysis module

---------

Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>

* updated substitute function to account for symbols with assumptions on them

* attempting to consolidate the typing

* Added sequence of commands as a test

* removing unused import

* Updating typing

* Implementing Konrads changes

* remove trailing whitespace

* added return statement

* reimplementing lost changes

* Implementing SympyAssumption

* made it so child classes of ExpressionRewriters do not need the decorator

* moved evaluation check into Assumptions _post_init_

* started assumptions tracking

* quick fix for custom max problem

* improved docstrings and added comments

* added reapply_all_assumptions

* formatting

* improving properties dict

* isort

* formatting

* began tests

* updated properties dict

* added tests

* formatting

* added comment on _add_assumption

* deleted test file

* fixing mypy issues

* fixing mypy issues

* fixing import for py3.10

* isort

* minor typo fix

* Added substitution methods

* implemented sympy substitutions,including wildcards

* modified substitute to allow arbitrary substitutions"

* improvements to wildcard subs

* fixed final bug in wildcard subs

* added hash to assumptions

* minor refactor

* added decorator to override custom max

* minor refactor after removing custom max

* began improving tests

* added classmethod to sympy_backend

* added classmethod to sympy_backend

* added tests for .with_sympy_max

* rename Relationals -> Comparators

* rename relationship->comparator

* minor typo fix

* re-adding assumptions after mistaken deletion

* changed from using float to literal_eval

* added more tests for assumptions

* minor fixes

* mypy fixes

* docstring updates;mypy fixes;wildcard improvements

* mypy fixes

* improved typehinting

* improved tracking of assumptions

* improved tracking of assumptions

* updating evaluate from main

* minor fixes

* gave _substitute default behaviour

* streamlined dataclass interactions

* deleting test file

* added_named_tuple

* bug fixes

* change from all caps to snake case

* minor refactor

* started testing substitutions

* moving some assumptions tests into basic tests

* updated focus + substitution logic

* added tests

* fixing docstring inconsistencies

* quick fixes from michals review

* Removed classmethod; moved logic to `parse_to_sympy`

* modified interpreter to override certain functions

* modified rewriter backend def

* removed test until we settle on impl

* bug fixes, test fixes

* deleted unwanted file

* mypy fix

* minor change

* refactor

* added function_overrides to sympyinterpreter

* updated sympybackend with new properties

* updated rewriter after changes to sympy backend

* modified backend after changes to interpreter

* removing unnecessary kwargs

* improved docstrings

* added tests for sympy_backend when using sympy max

* rename assume->assumption

* fix typing error

* test renaming

* typing fixes

* refactored into dataclasses

* removing tests from downstream branch

* added instruction set

* renaming assumption->assume

* typo

* another typo

* renamed kwarg to assumption

* fixing typing & usability

* updated tests to pass

* fixing imports

* deleted erroneous line

* added tests for history tracking

* fixing mypy issues

* refactored instructions

* refactored assumptions as child of dummy class

* modified tests after refactor

* made rewriters public

* made rewriters public

* deleting files

* exposed rewriter factory

* modified how substitutions are added

* minor refactor on substitutions; added factory  method

* improved logic on linked parameters

* updated tests after refactor

* added new ignore code to flake8

* remove unnecessary guards

* improving docstrings

* improving tests

* tighting typing

* added tests for linked parameters in focus

* added per-file ignore code for lambdas

* made wild chars stored in tuples rather than list

* removed None type from original_expression

* removed noqa

* simplified logic after Konrads comments

* minor typing typo (typ-o)

* fixing typos in docstring

* removed rewriter suffix from filename

* added rewriter instance for routines

* tightend up symbol retrieval logic

* improved docstrings

* fixing imports

* fixing imports

* clarified docstring

* removed guard on sympy type

* removed guard

* renamed routine.py > resources.py

* tidied docstring

* added tests

* added guard

* removed Generic parent class from ResourceRewriter

* fixing mypy

* updating docstrings

* minor factor on substitutions

* updating tests

* fixing attr error

* fixing tests

* once more

* previous commit was made in err

* removed testig code

* michals comments

* updated assumption properties derivation; improved docstrings

* updated tests

* updated apply_to_whole_routine and tests

---------

Co-authored-by: Avin Divakara <67309607+AVDiv@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: pqvr <work.vrpq@gmail.com>
Co-authored-by: Konrad Jałowiecki <dexter2206@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants