First time here? Checkout the FAQ!
x
0 votes
by (350 points)

Hello,

I'm trying to reproduce the example given in the "overview of workflow" videos (https://www.youtube.com/watch?v=Idt65RqX_50), but when I run the code I get the following error:

    '-gregion[1].num_IDs', 1,

    ^

SyntaxError: invalid syntax

which is very weird, because right before this line there is the same command but for gregion[0] ('-gregion[0].num_IDs', 1,), and there's no error there.
I double-checked the code and I can't find any differences between the example and what I wrote. 
Does anybody know what is happening?

1 Answer

0 votes
by (3.4k points)
Hello,

Could you provide the whole script causing the error?
by (350 points)
import os

from datetime import date

# import required carputils modules
from carputils import settings
from carputils import tools
from carputils import mesh
from carputils import testing
from numpy import array as nplist
from carputils import ep


def parser():
    parser = tools.standard_parser()
    group = parser.add_argument_group('experiment specific options')
    group.add_argument('--ionic_model', default='COURTEMANCHE',
                        choices=['TT2', 'COURTEMANCHE', 'HH'],
                        help= 'pick ionic model')
    grop.add_argument('--duration',
                        type=float, default=1000.,
                        help='duration of simulation (ms) (default is 1000.)')
    grop.add_argument('--sourceModel',
                        type=str, default='monodomain',
                        help='use mono- or bidomain')
    grop.add_argument('--stim-strength',
                        type=float, default=30.,
                        help='pick transmembrane current stimulus strenght in [uA/cm²] (default is 30.)')
    grop.add_argument('--stim-dur',
                        type=float, default=2.,
                        help='pick transmembrane current stimulus duration in [ms] (default is 2.)')
                        
    return parser

def jobID(args):
   
    today = date.today()
    return '{}_basic_{}'.format(today.isoformat(), args.duration)

@tools.carpexample(parser, jobID)
def run(args, job):

    ##### define mesh #####


    # Generate mesh, units in mm, centered around origin
    x = 5.0 #(mm)
    y = 5.0 #(mm)
    z = 1.0 #(mm)
    res = 0.1
    geom = mesh.Block(centre=(0.0,0.0,0.0), size=(x, y, z), resolution=res, etype='tetra')
    reg1 = mesh.BoxRegion((-x/2, -y/2, -z/2), (0, y/2, z/2), tag=10)
    geom.add_region(reg1)
    reg2 = mesh.BoxRegion((0, -y/2, -z/2), (x, y/2, z/2), tag=11)
    geom.add_region(reg2)
    geom.corner_at_origin()

    # Set fibre angle to 0°, sheet angle to 90° both on "endo" and "epi" surfaces
    geom.set_fibres(0, 0, 0, 0)
    
    # Generate and return base name
    meshname = mesh.generate(geom)


    ######## define ionic models and conductivities for each region #######

    imp_reg = ['-num_imp_regions', 2,
                #for the first region:

                '-imp_region[0].im', "COURTEMANCHE",
                '-imp_region[0]num_IDs', 1,
                '-imp_region[0].ID[0]', "10",    

                #for the second region:
                '-imp_region[1].im', "COURTEMANCHE",
                '-imp_region[1].im_param', "g_Kr*2., g_Ks*2", ##increase in potassium conductance
                '-imp_region[1]num_IDs', 1,
                '-imp_region[1].ID[0]', "11"]   

    g_reg = ['-num_gregions', 2,
             '-gregion[0].num_IDs', 1,
             '-gregion[0].ID[0]', 10,
             '-gregion[0].g_il', 0.174,
             '-gregion[0].g_it', 0.174,
             '-gregion[0].g_in', 0.174,
             '-gregion[0].g_el', 0.625,
             '-gregion[0].g_et', 0.625,
             '-gregion[0].g_en', 0.625
             '-gregion[1].num_IDs', 1,
             '-gregion[1].ID[0]', 11,
             '-gregion[1].g_il', 0.074,
             '-gregion[1].g_it', 0.074,
             '-gregion[1].g_in', 0.074,
             '-gregion[1].g_el', 0.025,
             '-gregion[1].g_et', 0.025,
             '-gregion[1].g_en', 0.025]


    ##### define stimulation #####

    E1_lower_bound = nplist([0, 0, z])
    E1_upper_bound = nplist([2*res, 2*res, z])


    electrode1 = mesh.block_region(geom, 'stimulus', 0, E1_lower_bound, E1_upper_bound, False)
    electrode = electrode1
    
    stim = ['-num_stim', 1,
            '-stimulus[0].stimtype', 0,
            '-stimulus[0].strength', 2500.0,     #(uA/cm²)
            '-stimulus[0].duration', 2.0,        #(ms)
            '-stimulus[0].start', 0,             #(ms)
            '-stimulus[0].npls', 1]

    #### define simulator options #####

    Src = ep.model_type_opts(args.sourceModel)
    num_par = [ '-dt', 100]
    IO_par = ['-spacedt', 0.1,
              '-timedt', 5.0]

    cmd = tools.carp_cmd()
    cmd += imp_reg
    cmd += g_reg
    cmd += stim + electrode
    cmd += num_par
    cmd += IO_par
    cmd += Src
    cmd = job.ID

    cmd += ['meshname', meshname,
            '-tend', args.duration,
            '-simID', simID]

    #### visualization ####
    if args.visualize:
        cmd += ['-gridout_i', 4,
                '-gridout_e', 4]


    # Run simulation
    job.carp(cmd)


if __name__ == '__main__':
    run()
by (100 points)
You are missing a comma at the end of the line preceding the one that's printed in the error:

             '-gregion[0].g_en', 0.625
             '-gregion[1].num_IDs', 1,
by (350 points)
Thank you! That was the problem indeed... but now I'm getting a different error:

Traceback (most recent call last):
  File "/home/mariaduda/Desktop/workflow.py", line 147, in <module>
    run()
  File "/usr/local/lib/python3.9/dist-packages/carputils/tools.py", line 528, in wrapped
    ret = run(args, job)
  File "/home/mariaduda/Desktop/workflow.py", line 134, in run
    '-simID', simID]
NameError: name 'simID' is not defined



The "fixed" version of the code:
import os

from datetime import date

# import required carputils modules
from carputils import settings
from carputils import tools
from carputils import mesh
from carputils import testing
from numpy import array as nplist
from carputils import ep


def parser():
    parser = tools.standard_parser()
    group = parser.add_argument_group('experiment specific options')
    group.add_argument('--ionic_model', default='COURTEMANCHE',
                        choices=['TT2', 'COURTEMANCHE', 'HH'],
                        help= 'pick ionic model')
    group.add_argument('--duration',
                        type=float, default=1000.,
                        help='duration of simulation (ms) (default is 1000.)')
    group.add_argument('--sourceModel',
                        type=str, default='monodomain',
                        help='use mono- or bidomain')
    group.add_argument('--stim-strength',
                        type=float, default=30.,
                        help='pick transmembrane current stimulus strenght in [uA/cm²] (default is 30.)')
    group.add_argument('--stim-dur',
                        type=float, default=2.,
                        help='pick transmembrane current stimulus duration in [ms] (default is 2.)')
                        
    return parser

def jobID(args):
   
    today = date.today()
    return '{}_basic_{}'.format(today.isoformat(), args.duration)

@tools.carpexample(parser, jobID)
def run(args, job):

    ##### define mesh #####


    # Generate mesh, units in mm, centered around origin
    x = 5.0 #(mm)
    y = 5.0 #(mm)
    z = 1.0 #(mm)
    res = 0.1
    geom = mesh.Block(centre=(0.0,0.0,0.0), size=(x, y, z), resolution=res, etype='tetra')
    reg1 = mesh.BoxRegion((-x/2, -y/2, -z/2), (0, y/2, z/2), tag=10)
    geom.add_region(reg1)
    reg2 = mesh.BoxRegion((0, -y/2, -z/2), (x, y/2, z/2), tag=11)
    geom.add_region(reg2)
    geom.corner_at_origin()

    # Set fibre angle to 0°, sheet angle to 90° both on "endo" and "epi" surfaces
    geom.set_fibres(0, 0, 0, 0)
    
    # Generate and return base name
    meshname = mesh.generate(geom)


    ######## define ionic models and conductivities for each region #######

    imp_reg = ['-num_imp_regions', 2,
                #for the first region:

                '-imp_region[0].im', "COURTEMANCHE",
                '-imp_region[0]num_IDs', 1,
                '-imp_region[0].ID[0]', "10",    

                #for the second region:
                '-imp_region[1].im', "COURTEMANCHE",
                '-imp_region[1].im_param', "g_Kr*2., g_Ks*2", ##increase in potassium conductance
                '-imp_region[1]num_IDs', 1,
                '-imp_region[1].ID[0]', "11"]   

    g_reg = ['-num_gregions', 2,
             '-gregion[0].num_IDs', 1,
             '-gregion[0].ID[0]', 10,
             '-gregion[0].g_il', 0.174,
             '-gregion[0].g_it', 0.174,
             '-gregion[0].g_in', 0.174,
             '-gregion[0].g_el', 0.625,
             '-gregion[0].g_et', 0.625,
             '-gregion[0].g_en', 0.625,
             '-gregion[1].num_IDs', 1,
             '-gregion[1].ID[0]', 11,
             '-gregion[1].g_il', 0.074,
             '-gregion[1].g_it', 0.074,
             '-gregion[1].g_in', 0.074,
             '-gregion[1].g_el', 0.025,
             '-gregion[1].g_et', 0.025,
             '-gregion[1].g_en', 0.025]


    ##### define stimulation #####

    E1_lower_bound = nplist([0, 0, z])
    E1_upper_bound = nplist([2*res, 2*res, z])


    electrode1 = mesh.block_region(geom, 'stimulus', 0, E1_lower_bound, E1_upper_bound, False)
    electrode = electrode1
    
    stim = ['-num_stim', 1,
            '-stimulus[0].stimtype', 0,
            '-stimulus[0].strength', 2500.0,     #(uA/cm²)
            '-stimulus[0].duration', 2.0,        #(ms)
            '-stimulus[0].start', 0,             #(ms)
            '-stimulus[0].npls', 1]

    #### define simulator options #####

    Src = ep.model_type_opts(args.sourceModel)
    num_par = [ '-dt', 100]
    IO_par = ['-spacedt', 0.1,
              '-timedt', 5.0]

    cmd = tools.carp_cmd()
    cmd += imp_reg
    cmd += g_reg
    cmd += stim + electrode
    cmd += num_par
    cmd += IO_par
    cmd += Src
    cmd = job.ID

    cmd += ['meshname', meshname,
            '-tend', args.duration,
            '-simID', simID]

    #### visualization ####
    if args.visualize:
        cmd += ['-gridout_i', 4,
                '-gridout_e', 4]


    # Run simulation
    job.carp(cmd)


if __name__ == '__main__':
    run()
by (100 points)
Part of your code:
    cmd += Src
    cmd = job.ID

Change this to
    cmd += Src
    simID = job.ID
Welcome to openCARP Q&A. Ask questions and receive answers from other members of the community. For best support, please use appropriate TAGS!
architecture, carputils, documentation, experiments, installation-containers-packages, limpet, slimfem, website, governance
MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], config: ["MMLorHTML.js"], jax: ["input/TeX"], processEscapes: true } }); MathJax.Hub.Config({ "HTML-CSS": { linebreaks: { automatic: true } } });
...