# Expected string or bytes-like object when calling Network(....).run(...)

**URL:** <https://brian.discourse.group/t/expected-string-or-bytes-like-object-when-calling-network-run/1199>\
**Category:** Support\
**Tags:** equations, refractoriness\
**Created:** [19 April 2024 00:19 UTC](https://brian.discourse.group/t/expected-string-or-bytes-like-object-when-calling-network-run/1199 "2024-04-19T00:19:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itq](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@itq](https://brian.discourse.group/u/itq)\
**Post date:** [19 April 2024 00:19 UTC](https://brian.discourse.group/t/expected-string-or-bytes-like-object-when-calling-network-run/1199/1 "2024-04-19T00:19:11Z")

</div>

Hey there! So my code is the following:

```python
from brian2 import *

if __name__ == ' __main__':

    _start = 0
    _stop = 1_000 * ms
    _step = 0.2 * ms
    times = np.linspace(_start, _stop, int((_stop - _start) / _step + 1))
    connectivity_matrix = np.random.randint(0, 10, (10, 10))

    # Create a TimedArray
    values = 1 * mV * ones(len(times))
    v_ext_array = 1 * mV * np.repeat([values], len(connectivity_matrix), axis=0)

    # Correct TimedArray setup
    v_ext = TimedArray(v_ext_array, dt=_step)
    tau = 5 * ms
    g = 0 * mV
    v_0 = -52 * mV
    v = v_0
    t_mbr = 20 * ms
    eqs = """
    dv/dt = (v_0 - v + g + v_ext(t, i)) / t_mbr : volt (unless refractory)
    dg/dt = -g / tau : volt (unless refractory) 
    """
    neu = NeuronGroup( # create neurons
        N=len(connectivity_matrix),
        model=eqs,
        method="linear",
        threshold="v > v_th",
        reset="v = v_rst; w = 0; g = 0 * mV",
        refractory=True,
        name="default_neurons",
    )

    ################################################
    # Then, populate the synapses
    ################################################

    sources, targets = connectivity_matrix.nonzero()
    syn = Synapses(
        neu, neu, "w : volt", on_pre="g += w", delay=-1.8 * ms, name="default_synapses"
    )
    syn.connect(i=sources, j=targets)

    weight_per_synapse = 0.275 * mV

    syn.w[:] = connectivity_matrix[(sources, targets)] * weight_per_synapse
    spike_monitor = SpikeMonitor(neu)

    net = Network(neu, syn, spike_monitor)

    # run simulation
    print("Started Modeling Process")
    net.run(duration=1_000 * ms, report="stdout", report_period=100 * second)

```

I’m running into an issue during the `net.run(...)` step - which makes me think that this is a “run-time” issue when it tries to run the simulation? I’m not really sure how to get around the issue though… I did some searching and I found [Issue with running the model](https://brian.discourse.group/t/issue-with-running-the-model/604) but it doesn’t really look relevant, other than that we are facing the same bug

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [19 April 2024 08:58 UTC](https://brian.discourse.group/t/expected-string-or-bytes-like-object-when-calling-network-run/1199/2 "2024-04-19T08:58:09Z")

</div>

Hi @itq . And yet again, this error message isn’t great… The error isn’t directly related to the `run` call itself. When you call `run`, Brian prepares the network, generated the code, etc., so this is often the place where you get errors when something went wrong. This is why Brian gives an additional hint at the end of the error message, in your case:

```pytb
brian2.core.base.BrianObjectException: Error encountered with object named 'default_neurons_stateupdater'.
Object was created here (most recent call only, full details in debug log):
  File '/home/mstimberg/scratch/run_error.py', line 26, in <module>
    neu = NeuronGroup( # create neurons

An error occurred when preparing an object. (See above for original error message and traceback.)

```

This tells you that the actual problem is in the definition of the `NeuronGroup`. Further up, you get the actual error which states: “TypeError: expected string or bytes-like object, got ‘bool’”. So at some point, Brian expected to find a string but received a boolean value. From your `NeuronGroup` definition you can see that this is most likely the `refractory=True` argument, since this is the only boolean you hand over. And indeed, you cannot give a True/False value as the argument for the refractoriness, it needs to be either:

- a time, that states the refractory time after each spike
- a string that evaluates to such a time (in this case, it could be different for each cell, random, etc.)
- a string that evaluates to a boolean value, stating whether the cell should stay refractory (this is mostly used in cells that do not have a reset mechanism to prevent that spikes are counted for every time step where the membrane potential is above the threshold).

See [Refractoriness — Brian 2 2.6.0 documentation](https://brian2.readthedocs.io/en/stable/user/refractoriness.html) for more details

I am not quite sure what you wanted to say with `refractory=True`. Technically, you can make this code run by writing the value as a string instead, i.e. `refractory="True"`. But this would mean that the neuron is always refractory and never spikes, which is quite likely not what you want 😉 Most likely you want to use something like `refactory=2*ms` or `refractory="2*ms"` (both are equivalent)?

---

<div class="post-metadata">

**Author:** ![itq](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@itq](https://brian.discourse.group/u/itq)\
**Post date:** [19 April 2024 21:55 UTC](https://brian.discourse.group/t/expected-string-or-bytes-like-object-when-calling-network-run/1199/3 "2024-04-19T21:55:40Z")

</div>

Ugh, I’m so sorry thank you! In hindsight, I have no idea why I made that change. In any case, everything works now, so thank you! I really appreciate all your help and patience.
