Welcome to the forums. Please post in English or French.

You are not logged in.

#1 2023-11-20 16:05:06

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

[SOLVED sort of]Need help with script running export file fromTerminal

Hi,
During training I received from Johannes Ackva a script to run Code_Aster's export file from terminal. I got used to this way of running a simulation. The script has been written for non-singularity version of Salome_Meca. Now I'd like to change it to be able to run it for the most recent version of C_A. Could anyone help me with that?

Basically what script does is checking if there's an export file, if the export file is really an export file and if both conditions are met it copies/saves the export file under new name "the-export-file", runs it and deletes it. I'd like to leave it that way.

Salome_Meca 2022 sif file is placed in /opt/sm/

#! /bin/sh
#. /home/user/sm20/appli_V2020.0.1_universal_universal/env.d/envProducts.sh (this line I don't know how to change for singularity version, there's no  folder there)
if test $# -eq 0 ; then
       echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
       echo "!!                                                                                       !!"
       echo "!!      The Code-Aster start file (export) is lacking         !!"
       echo "!!                                                                                       !!"
       echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
       echo "  "
       exit 1
fi
for i; do
     if test -f $i; then
       cp $i  the-export-file
        singularity exec /opt/sm/salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif salome shell -- as_run the-export-file
       rm the-export-file
     else
       echo "  "
       echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
       echo "!!                                                                                              !!"
       echo "!! Given argument is not a Code-Aster start file (export)    !!"
       echo "!!                                                                                              !!"
       echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
       echo "  "
     fi
done

At this point I'm getting error that there's no "the-export-file" and the simulation stops. I have little to none coding experience, but for 100% second line is wrong. Is there a way to check what's folder path to envProducts.sh in singularity container?

Last edited by k_zurawski (2023-11-27 21:04:09)


regards,
Krzysztof

Offline

#2 2023-11-20 16:26:24

mf
Member
Registered: 2019-06-18
Posts: 407

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Hello,

the folder/file you're searching inside the container is under

/opt/salome_meca/appli_V2022.1.0_scibian_univ/env.d

There you will find the script envProducts.sh

You can check that by starting the container via

./salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif --shell

Not sure if that will work the same way, though. You'd have to launch your script inside the container,

Mario.


Attachments:
Bildschirmfoto vom 2023-11-20 16-25-31.png, Size: 50.17 KiB, Downloads: 19

Offline

#3 2023-11-20 16:29:20

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Thank you.

Do you know what envProducts.sh is for? What it does?


regards,
Krzysztof

Offline

#4 2023-11-20 16:33:06

mf
Member
Registered: 2019-06-18
Posts: 407

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Hello,

not particularily, in the header it says "# SALOME_MECA V2022 - Environnement file for the prerequisites and tools".

There's a lot of checking for installed prerequisites and a boatload of path definitions. So I am intended to say 'it prepares the environment for Code Aster'. I have no idea if this is true, though,

Mario.

Last edited by mf (2023-11-20 16:33:50)

Offline

#5 2023-11-20 16:38:27

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 4,049

Re: [SOLVED sort of]Need help with script running export file fromTerminal

hello

what a complicated way to do something very simple
once i have a valid export file
i just open the singularity shell

$HOME/salome_meca-lgpl-2021.1.0-1-20220405-scibian-9.sif shell

and run this command

xterm -e as_run the_export_file.export

just one trouble if the export file is not valid it may result in a crash

in fact i sandboxed the container and the opening time is divided by a factor of several tens

jean pierre aubry


consider reading my book
freely available here https://framabook.org/beginning-with-code_aster/

Offline

#6 2023-11-20 16:43:55

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Well, there is asbin alias setup in .bashrc to run the script. So in this case I have two advantages. In study folder I just write asbin study.export and the second is that there is no export file alteration. When I run it manually there are folder paths added to export file. So when I reuse the file I have to change more than just study filenames (med, rmed, resu, mess, comm etc.).

Last edited by k_zurawski (2023-11-20 16:50:47)


regards,
Krzysztof

Offline

#7 2023-11-20 16:54:07

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

what does -e before as_run mean?


regards,
Krzysztof

Offline

#8 2023-11-20 17:01:26

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 4,049

Re: [SOLVED sort of]Need help with script running export file fromTerminal

xterm -e program_file
means excecute
program_file within xterm

it open an xterm window outside the singularity shell
i prefer it that way, just that


consider reading my book
freely available here https://framabook.org/beginning-with-code_aster/

Offline

#9 2023-11-20 22:03:09

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Thank you


regards,
Krzysztof

Offline

#10 2023-11-21 10:37:05

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Jean Pierre,
Could you write step by step commands to run the simulation by running export file from terminal? But not from Xterm, just the regular one. I tried yesterday, but sadly I can't announce success...
As I said, I'm illiterate when it comes to programming, the same applies to Singularity.
Thank you in advance.


BTW can someone point me to some good training material of Singularity? I watched something on YT, but couldn't find anything helpful. Just some brief description to someone familiar with Docker etc. I'm not that guy.


regards,
Krzysztof

Offline

#11 2023-11-21 11:41:35

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 4,049

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Could you write step by step commands to run the simulation by running export file from terminal? But not from Xterm, just the regular one. I tried yesterday, but sadly I can't announce success...

i am not exactly sure of what you mean
i think it is not possible from a regular linux terminal you have to go to the singularity shell
by running

$HOME/salome_meca-lgpl-2021.1.0-1-20220405-scibian-9.sif shell

and in this shell running

as_run the_export_file.export

should do the job in the singularity shell, at least it does on my komputer

As I said, I'm illiterate when it comes to programming,

i am afraid i am just a small step above

the same applies to Singularity.

i have been unable to find any valuable [or understandable] dokumentation about singularity
some posts in this forum helped me somehow

some by hberro, i have to thank him here

the following was just guess plus trial and error and a few head scratching!

Last edited by jeanpierreaubry (2023-11-21 11:44:23)


consider reading my book
freely available here https://framabook.org/beginning-with-code_aster/

Offline

#12 2023-11-21 12:52:10

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

i am not exactly sure of what you mean
i think it is not possible from a regular linux terminal you have to go to the singularity shell
by running

$HOME/salome_meca-lgpl-2021.1.0-1-20220405-scibian-9.sif shell

So your study (export file) is in $HOME/ when you run it? Am I right?

the following was just guess plus trial and error and a few head scratching!

It seems I won't have any hair left on my head when I master C_A + Singularity...


regards,
Krzysztof

Offline

#13 2023-11-21 13:03:02

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

in my case this is the result:

user@MALUCH:/opt/sm$ ls
README  bin  resources  salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif
user@MALUCH:/opt/sm$ salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif shell
salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif: command not found
user@MALUCH:/opt/sm$ salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif shell
salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif: command not found
user@MALUCH:/opt/sm$

I have no idea why it runs on your machine and on my not.


regards,
Krzysztof

Offline

#14 2023-11-21 13:58:26

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 4,049

Re: [SOLVED sort of]Need help with script running export file fromTerminal

So your study (export file) is in $HOME/ when you run it? Am I right?

no !
but salome_meca-lgpl-2021.1.0-1-20220405-scibian-9.sif  is at the root of my home directory
i think  i has to be there
that does not seems to be the case with you


consider reading my book
freely available here https://framabook.org/beginning-with-code_aster/

Offline

#15 2023-11-21 14:18:00

mf
Member
Registered: 2019-06-18
Posts: 407

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Hello,
I just briefly describe what I do, my container is in my home directory (  ~/ or   $HOME or   ${HOME} ), I think every other location is very impractical. Current working directory is also ~/, you can check the working dir with the 'pwd' command.

With

singularity run --app install salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif

the container is installed. Because I do not use code_aster at the command line, I would normally run SM now. But in your case I would type:

./salome_meca-lgpl-2022.1.0-1-20221225-scibian-9 shell

The ./ is CRUCIAL (it even says so in the text after container installation!), it executes the file (this is a common command in Linux). In Msr. Aubry's case it is missing maybe because he made it executable beforehand, but I do not know. Now you are in the container shell where you can type

as_run the_export_file.export

or the other command above with xterm. As you can tell by the attached screenshots, this works.

Mario.

Last edited by mf (2023-11-21 14:21:16)


Attachments:
Bildschirmfoto vom 2023-11-21 14-15-.zip, Size: 600.65 KiB, Downloads: 21

Offline

#16 2023-11-21 14:23:27

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 4,049

Re: [SOLVED sort of]Need help with script running export file fromTerminal

humm my mistake i typed it too fast previously
to run the singularity shell i do as follow

singularity run -B /dedalus /home/dedalus/salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif shell

with the following explanation

singularity run :
to run the following command

-B /dedalus :
to bind (give access) to the dir named dedalus at the root of my system
all my code_aster problems are located in sub dirs of that dir
this may be omitted if you run files within $HOME

/home/dedalus :
is my $HOME dir
/salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif :
is the salome_meca container

shell :
to launch the shell


consider reading my book
freely available here https://framabook.org/beginning-with-code_aster/

Offline

#17 2023-11-21 22:49:06

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

Thank you mf and Jean Pierre.

A word of explanation is needed. I don't have access to Linux machine now and I don't know if or when will it change. I have to use WSL to run Salome_Meca. Thanks to Hassan Berro's effort the VM works. I had problems with paravis on that VM and other problems with Windows port of Salome_Meca 2021. So I decided to use the newest Salome and Paraview standalone prepared for Windows plus run simulation on the latest version of C_A in terminal/PowerShell.

Thanks to you Guys I was able to run simulation in PowerShell. Evidence (input files are in my Downloads Windows folder):

 ---------------------------------------------------------------------------------
                                            cpu    système    cpu+sys     écoulé
 ---------------------------------------------------------------------------------
   Préparation de l'environnement          0.00       0.00       0.00       0.00
   Copie des données                       0.06       0.03       0.09       0.10
   Exécution de Code_Aster                 7.94       3.32      11.26      13.83
   Copie des résultats                     0.04       0.04       0.08       0.13
 ---------------------------------------------------------------------------------
   Total                                   8.45       3.51      11.96      14.74
 ---------------------------------------------------------------------------------

as_run 2021.0

------------------------------------------------------------
--- DIAGNOSTIC JOB : OK
------------------------------------------------------------


EXIT_CODE=0
Singularity>

Now I have almost everything I need. I'd like to simplify the way to run the simulation. Maybe bind a Windows folder to /Home/User?
You may add an alias to .bashrc file to run container. So in my case if all the studies would be in Downloads subdirectories entry in bashrc would look like this:

alias sm22='/opt/sm$ singularity run -B /mnt/c/Users/KrzysztofZurawski/Downloads/ salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif shell'

Then you can simply write in terminal sm22 to run the container.


regards,
Krzysztof

Offline

#18 2023-11-21 22:56:28

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

The alias doesn't work. I think I won't get rid of a sort of script, like the one I added at the beginning of this thread. I'll park this one for now.


regards,
Krzysztof

Offline

#19 2023-11-21 23:28:24

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

On second thought...

...for someone who would like to run simple command from terminal and your user folder in Linux is just named user:

If you place salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif anywhere else in the system (in this case /opt/sm) create empty file in your /home/user and name it .sm22 (dot before the file makes it hidden)
add these lines to the file:

#! /bin/sh
singularity run /opt/sm/salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif shell

save and close

add a line anywhere where aliases are in your hidden .bashrc file (the .bashrc file is in your home directory):

alias sm22='/home/user/.sm22'

save and close

Make .sm22 executable and reload .bashrc by writing in terminal:

chmod +x ~/.sm22
source ~/.bashrc

If all went ok then you may simply run terminal and write sm22 and it will run.

If you have an export file, cd to the location and run it by writing:

as_run example.export

voila!

Last edited by k_zurawski (2023-11-21 23:52:33)


regards,
Krzysztof

Offline

#20 2023-11-21 23:31:00

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

What was left is mounting/linking
/mnt/c/Users/KrzysztofZurawski/Downloads/

to my /home/user directory.


regards,
Krzysztof

Offline

#21 2023-11-27 21:03:09

k_zurawski
Member
From: Gdansk
Registered: 2010-03-13
Posts: 276

Re: [SOLVED sort of]Need help with script running export file fromTerminal

well... for part of this conversation I tried to solve already solved problem. By mistake I discovered that I don't have to run singularity inside wsl "VM". Well, this has already been prepared and if you are using what Hassan Berro prepared, after running

wsl -d smeca

you simply run

as_run exampleexportfile.export

and that's it. It works flawlessly...

So to sum up -
all I have written before applies to singularity installed directly on Linux machine. There's no need to change anything in shared "VM".

Last edited by k_zurawski (2023-11-27 21:18:22)


regards,
Krzysztof

Offline