Usage TaylorSeries.jl in to packages with different settings

I am using the TaylorSeries.jl in two independent packages (let’s say A.jl and B.jl), but I use them in one project.

The TaylorSeries.jl in A.jl is initialized as:

using TaylorSeries
function __init__()
    set_variables("dx dy dE",order=5)
end

In the package B.jl am using more variables:

using TaylorSeries.jl
function __init__()
    set_variables("x y dx dy dE",order=5)
end

When I use these packages in the project as

using A.jl
using B.jl

the setting of B.jl rewrites the setting of A.jl. It seems that both A.jl and B.jl share the same set of TaylorSeries. jl internal variables: e.g.
A.TaylorSeries.coeff_table gives the same result as B.TaylorSeries.coeff_table

Does anybody know if this can be fixed somehow?

Hi!

Thanks for posting your question and welcome to Julia!

You are right, in TaylorSeries.jl the multivariable case uses internal tables which behave as global variables; those tables have the information of what specific coefficient is associated with what monomial. Then, loading B.jl after A.jl changes those tables, which can certainly be the source of problems. If I recall correctly, this is mentioned in the documentation.

I do not know your actual problem, or if dx dy dE in A.jl represent the same variables in B.jl. Assuming that the names of the variables represent the same quantities in both packages, my initial suggestion is to use the same variables and ordering in A.jl and B.jl. This is certainly a waste of precious memory for A.jl, but should allow that everything works fine.

Thanks for the answer. Your suggested solution is one of the options.

I wonder if there is any standard approach to having internal tables of TaylorSeries.jl independent for A,jl and B.jl. Probably it is a property of Julia, that internal tables of a module are shared with all active modules that use it. If this is true, I have to handle that somehow …

The issue here is related to a design decision we made long time ago in TaylorSeries.jl, and not to Julia. Honestly, I see no simple way how to generalize it to two (a-priori weakly related) packages.

In TaylorSeries we also have the possibility of using nested Taylor1s. Have you explore that? While the possibility exists, there is a lot of work to make the package user friendlier (and clear) when dealing with nested Taylor1s. Be aware that you may loose performance.

As I suggested previously, you should use the variables consistently across both packages, and that the variables you assign (say dx) mean the same in both. Not knowing more details of your actual application makes it difficult to help.