# ArgumentError: u names not unique. Repeated names:

**URL:** https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386
**Category:** Modelling & Simulations
**Tags:** controlsystems
**Created:** [December 10, 2023, 8:02pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386 "2023-12-10T20:02:08Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 10, 2023, 8:02pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/1 "2023-12-10T20:02:08Z")

</div>

Hi,

I’m getting this error when using `connect`. The error is pretty self-explanatory and the solution is workable.

However, every time I’m getting that error, I actually have two inputs that have the same name because they are intended to receive the same input signal. So `connect` might as well merge them, rather than me having to rename them to `in1` and `in2` and add a splitter for the name `in`.

Is there any way to get such behavior? I might also consider submitting a patch, but I’m not really blessed with much free time these days.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [December 10, 2023, 8:08pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/2 "2023-12-10T20:08:06Z")

</div>

I’m not sure I fully understand the circumstances you’re getting those errors in - do you have a small example showcasing the error?

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 10, 2023, 8:46pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/3 "2023-12-10T20:46:30Z")

</div>

```julia
sys_1=named_ss(ssrand(1,2,2), u=[:in_x, :in_y], y=:out_z, x=[:x1, :x2])
sys_2=named_ss(ssrand(1,2,2), u=[:in_y, :in_z], y=:out, x = [:x3, :x4])
sys_connect = connect([sys_1, sys_2], [:out_z => :in_z]; w1 = [:in_x, :in_y], z1 = :out)

```

`sys_1` and `sys_2` both take the input `in_y`. I would like those two inputs to appear as a single input in `sys_connect`. Currently, I would do this is by renaming the inputs to `in_y1` and `in_y2`, then creating a splitter for `in_y` and connect the outputs of the splitter to the respective inputs of each system. I was wondering if there is a way to skip that step, because for me, the logical consequence of two inputs being named the same is to treat them as being the same. The same may or may not make sense for outputs, but that requires addition and it’s also not my current problem, so I don’t want to discuss that here.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [December 10, 2023, 9:13pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/4 "2023-12-10T21:13:29Z")

</div>

Sorry, what package is `connect` from? This does not seem to be from Base, so I think you’ll want to direct that feature request to the package in question.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [December 10, 2023, 9:27pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/5 "2023-12-10T21:27:28Z")

</div>

I’m afraid it is very difficult to understand what you are asking about. What packages are you using? Please include fully runnable code with _all_ the necessary `using` or `import` statements.

I’m afraid the thread title itself is far from self-explanatory. In general, it is recommended to read the following post, which can help write questions in a clear way:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 11, 2023, 6:38am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/6 "2023-12-11T06:38:35Z")

</div>

The `connect` in question comes from [RobustAndOptimalControl.jl](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/#Connecting-systems-together) and I agree that it can be somewhat hard to use.

The relevant code that throws the error even contains the following comment

```julia
# TODO: If some name below is repeated, perhaps the B matrix can be reduced in width?
# This could be optional, i.e., unique_names=true

```

I’ll try to think about a way of supporting this without introducing a footgun.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 11, 2023, 8:03am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/7 "2023-12-11T08:03:22Z")

</div>

@maltee1 please try out this branch and see if it makes the connection experience smoother in this case

> <https://github.com/JuliaControl/RobustAndOptimalControl.jl/pull/99>

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 11, 2023, 1:58pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/8 "2023-12-11T13:58:24Z")

</div>

@Sukera @DNF Apologies, I was too focused on control theory, so I forgot that you can do other things with julia…

@baggepinnen That appears to be what I’m looking for, however, it only seems to work on continuous systems. For a discrete system, it prints the new Error, despite `unique = false` being set.  
I really appreciate your outstanding “customer” service, is there somewhere I can donate to you?

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 11, 2023, 3:19pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/9 "2023-12-11T15:19:36Z")

</div>

> [@maltee1](#):
>
> it only seems to work on continuous systems. For a discrete system, it prints the new Error, despite `unique = false` being set.

Would you mind sharing an example that exposes this? I tried the following and it works fine

```julia
# Discrete
s1 = ssrand(1,2,2, Ts=1)
s2 = ssrand(1,2,2, Ts=1)
sys_1 = named_ss(s1, u=[:in_x, :in_y], y=:out_z, x=[:x1, :x2])
sys_2 = named_ss(s2, u=[:in_y, :in_z], y=:out, x = [:x3, :x4])

@test_throws "u names not unique. Repeated names: [:in_y] To allow connecting a single input signal to several inputs with the same name, pass `unique = false`." connect([sys_1, sys_2], [:out_z => :in_z]; w1 = [:in_x, :in_y], z1 = :out)

sys_connect = connect( # Works fine
    [sys_1, sys_2],
    [:out_z => :in_z];
    w1 = [:in_x, :in_y],
    z1 = :out,
    unique=false
)

```

> [@maltee1](#):
>
> I really appreciate your outstanding “customer” service, is there somewhere I can donate to you?

Thanks! User feedback and detailed error reports is plenty sufficient 😉

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 12, 2023, 8:28am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/10 "2023-12-12T08:28:09Z")

</div>

I wrongly believed it was due to the system being discrete, but apparently that has nothing to do with it. I can’t really tell what exactly triggers it, but here’s an example I’ve reduced as much as I could:

```julia
using RobustAndOptimalControl

sys_1 = named_ss(ssrand(1,3,2), u=[:in_a, :in_b, :in_c], y=[:ui_ref], x=[:x1, :x2])
sys_2 = named_ss(ssrand(1,3,2), u=[:in_e, :in_c, :in_d], y=:out_a, x=[:x3, :x4]);
sys_3 = named_ss(ssrand(1,1,1), u=:in_d, y=:out_e, x=:x5);
sys_ctrl = connect([sys_1, sys_2, sys_3],
    [:out_a => :in_a, :out_e => :in_e];
    w1 = [:in_b, :in_c, :in_d],
    z1 = :ui_ref,
    unique = false)

```

fails with:

```julia
ERROR: ArgumentError: u names not unique. Repeated names: [:in_d] To allow connecting a single input signal to several inputs with the same name, pass `unique = false`.

```

`append` with the three systems still seems to work.  
I assume my code is calling [this method](https://github.com/JuliaControl/RobustAndOptimalControl.jl/blob/c9666df5012e786da60766165f0645a228b0c1ea/src/named_systems2.jl#L499), which doesn’t have the `unique` argument.

I can’t tell why this particular example would call that method, but maybe you can.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 12, 2023, 8:41am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/11 "2023-12-12T08:41:28Z")

</div>

Thanks for the example! The fix turned out to be simple, I’ve pushed a fix to the PR branch

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 12, 2023, 8:49am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/12 "2023-12-12T08:49:35Z")

</div>

I thought I tested multiple nonunique inputs because I suspected that to be the issue, turns out I didn’t test properly.

It works. Wonderful!

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 13, 2023, 9:15am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/13 "2023-12-13T09:15:40Z")

</div>

@baggepinnen Now I’m trying to combine two systems using `append` and am hoping to have their nonunique outputs merged as well, which it doesn’t do. `connect` apparently requires me to specify at least one connection. If you get the chance, do you think you could extend the behavior of `unique = false` to the `append` function?

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 14, 2023, 10:51am UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/14 "2023-12-14T10:51:43Z")

</div>

> [@maltee1](#):
>
> Now I’m trying to combine two systems using `append` and am hoping to have their nonunique outputs merged as well

I’m not sure if this sounds correct, you are talking about the function `append` which performs block-diagonal concatenation, i.e., the operation below

```julia
 u1 ┌───┐ y1
───►│ P1├──► u1 ┌─────┐ y1
    └───┘ ──►│ ├──►
              ────► ──►│ P12├──►
 u2 ┌───┐ y2 u2 └─────┘ y2
───►│ P2├──►
    └───┘

```

but you’re asking for it to behave like vertical concatenation `P12 = [P1; P2]`

```julia
 u ┌───┐ y1
───►│ P1├──► ┌─────┐ y1
    └───┘ ──►│ ├──►
              ────► u │ P12├──►
 u ┌───┐ y2 └─────┘ y2
───►│ P2├──►
    └───┘

```

Can’t what you’re asking for be realized using the `connect` function?

```julia
s1 = ssrand(1,2,2)
s2 = ssrand(1,2,2)
sys1 = named_ss(s1, "A", u=[:u1, :u2]) # Input u2 appears in both systems
sys2 = named_ss(s2, "B", u=[:u2, :u3])

sys12 = connect(
    [sys1, sys2],
    Pair{Symbol, Symbol}[]; # Empty connection vector of the correct type
    w1 = [:u1, :u2, :u3],
    z1 = [sys1.y; sys2.y],
    unique = false
)

```

The resulting system has the input `u2` merged.

```julia-repl
julia> sys12 = connect([sys1, sys2], Pair{Symbol, Symbol}[], w1 = [:u1, :u2, :u3], z1 = [sys1.y; sys2.y], unique=false)
NamedStateSpace{Continuous, Float64}
A = 
 -0.06812632965152318 0.5720015099467834 0.0 0.0
 -0.9590957208034123 -1.2581734396885567 0.0 0.0
  0.0 0.0 0.20021007961714576 -0.7677092543034114
  0.0 0.0 0.6655398066449922 -1.8810324473875886
B = 
 -0.5285225476394938 -1.3112160323503186 0.0
 -0.6058648756516474 -1.1713675813478548 0.0
  0.0 -0.3626155828058133 1.6492509268100324
  0.0 1.1480210367263297 -0.4767449301439349
C = 
 0.8695036855393466 -0.8001568554043171 0.0 0.0
 0.0 0.0 -0.8301044609973323 -0.6223243969601403
D = 
 0.5287883123468724 1.3107581033813325 0.0
 0.0 -0.37456658050500763 3.507504356656879

Continuous-time state-space model
With state names: Ax1##feedback#226 Ax2##feedback#226 Bx1##feedback#226 Bx2##feedback#226
     input names: u1 u2 u3
     output names: Ay By

```

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 18, 2023, 8:08pm UTC](https://discourse.julialang.org/t/argumenterror-u-names-not-unique-repeated-names/107386/15 "2023-12-18T20:08:36Z")

</div>

Apologies… I tried that, but apparently I got the syntax wrong and assumed it didn’t work. Thanks a lot!
