# How do I import t\_nounits with a different name than t in ModelingToolkit?

**URL:** <https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640>\
**Category:** Modelling & Simulations\
**Tags:** question, modelingtoolkit\
**Created:** [August 26, 2024, 6:10pm UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640 "2024-08-26T18:10:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmc4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pmc4/32/211593_2.png) [@pmc4](https://discourse.julialang.org/u/pmc4)\
**Post date:** [August 26, 2024, 6:10pm UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640/1 "2024-08-26T18:10:01Z")

</div>

Hi everyone! I’ve been playing with ModelingToolkit for several weeks, but there’s still one issue I haven’t been able to fully understand.

In the [`NEWS.md`](https://github.com/SciML/ModelingToolkit.jl/blob/master/NEWS.md) file of the github repo, it states:

- ModelingToolkit.jl now exports common definitions of `t` (time independent variable) and `D` (the first derivative with respect to `t`). Any models made using ModelingToolkit.jl should leverage these common definitions. There are three variants:
  - `t` and `D` use DynamicQuantities.jl units. This is the default for standard library components.
  - `t_unitful` and `D_unitful` use Unitful.jl units.
  - `t_nounits` and `D_nounits` are unitless.

In every example of the docs of ModelingToolkit `t_nounits` and `D_nounits` is used, e.g.:

```julia
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D

@mtkmodel FOL begin
    @parameters begin
        τ = 3.0 # parameters
    end
    @variables begin
        u(t) = 0.0 # dependent variables
    end
    @equations begin
        D(u) ~ (1 - u) / τ
    end
end

using DifferentialEquations: solve
@mtkbuild fol = FOL()
prob = ODEProblem(fol, [], (0.0, 10.0), [])
sol = solve(prob)

```

Reading all of this, and also [this answer of the forums](https://discourse.julialang.org/t/modelingtoolkit-news/111126/2), I’d understand that the name `t` and `D` is just a placeholder of `t_nounits` and `D_nounits` and one could use, for example, `t_nounits as x` and `D_nounits as Dx`. However, if we do so and execute the same code:

```julia
using ModelingToolkit
using ModelingToolkit: t_nounits as x, D_nounits as Dx

@mtkmodel FOL begin
    @parameters begin
        τ = 3.0 # parameters
    end
    @variables begin
        u(x) = 0.0 # dependent variables
    end
    @equations begin
        Dx(u) ~ (1 - u) / τ
    end
end

using DifferentialEquations: solve
@mtkbuild fol = FOL()
prob = ODEProblem(fol, [], (0.0, 10.0), [])
sol = solve(prob)

```

we get the following error

```julia
ERROR: ArgumentError: Differential w.r.t. variable (t) other than the independent variable (x) are not allowed.

```

I think this happens because Dx is still interpreted as Differential(t). I would have expected that D\_nounits = Differential(t\_nounits) so importing them with a different name was just a label and ModelingToolkit translated everything under the hood.

Could someone enlighten me about this issue, please?

PS: if one want’s to really use x, a possible solution is to use the `@inependent_variables` macro and then define the derivative, i.e.,

```julia
using ModelingToolkit

@independent_variables x
D = Differential(x)
@mtkmodel FOL begin
    @parameters begin
        τ = 3.0 # parameters
    end
    @variables begin
        u(x) = 0.0 # dependent variables
    end
    @equations begin
        D(u) ~ (1 - u) / τ
    end
end

using DifferentialEquations: solve
@mtkbuild fol = FOL()
prob = ODEProblem(fol, [], (0.0, 10.0), [])
sol = solve(prob)

```

This, however, keeps raising the warning

```julia
┌ Warning: Independent variable x should be defined with @independent_variables x.
└ @ ModelingToolkit ~/.julia/packages/ModelingToolkit/GJiqn/src/utils.jl:119

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 27, 2024, 3:10pm UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640/2 "2024-08-27T15:10:13Z")

</div>

This seems like a bug in the macro. Report it?

---

<div class="post-metadata">

**Author:** ![pmc4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pmc4/32/211593_2.png) [@pmc4](https://discourse.julialang.org/u/pmc4)\
**Post date:** [August 27, 2024, 3:49pm UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640/3 "2024-08-27T15:49:06Z")

</div>

I’ll open an issue regarding the `@independent_variables` macro.

Regarding the behaviour of the first issue, `using ModelingToolkit: t_nounits as x, D_nounits as Dx`. Is it also a bug or I understood wrongly the use of `t_nounits`?

---

<div class="post-metadata">

**Author:** ![ven-k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ven-k/32/11915_2.png) [@ven-k](https://discourse.julialang.org/u/ven-k)\
**Post date:** [August 27, 2024, 3:49pm UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640/4 "2024-08-27T15:49:32Z")

</div>

The error is new. A new check was added for independent var last month here: [Check that independent variables are defined as @parameters · SciML/ModelingToolkit.jl@d95f966 · GitHub](https://github.com/SciML/ModelingToolkit.jl/commit/d95f9664293e50978d77348a6ada8e2a16537f14) and [Issue warning instead of error when independent variable is not a par… · SciML/ModelingToolkit.jl@2b67034 · GitHub](https://github.com/SciML/ModelingToolkit.jl/commit/2b670348c210ea8ec9d90b38847adc3898d64749).

I’ll suitably update the macro.

---

<div class="post-metadata">

**Author:** ![hersle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hersle/32/211689_2.png) [@hersle](https://discourse.julialang.org/u/hersle)\
**Post date:** [August 30, 2024, 10:10am UTC](https://discourse.julialang.org/t/how-do-i-import-t-nounits-with-a-different-name-than-t-in-modelingtoolkit/118640/5 "2024-08-30T10:10:59Z")

</div>

`@independent_variables` was introduced in [Create independent variables with @independent\_variables by hersle · Pull Request #2862 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/pull/2862) as the standard way of doing it.

The warning you see is a small bug in the `@mtkmodel` macro. I’m trying to fix it in [Fix @mtkmodel independent variable generation by hersle · Pull Request #3001 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/pull/3001).
