GMLC-TDC / helics-cli

HELICS Command Line Interface
BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

The error of running the example #42

Open lzheng28 opened 3 years ago

lzheng28 commented 3 years ago

When I run the example of pi-exchange, the following error happens

(py3.7-helics-2.6.1) lei@lei-VirtualBox:~/Install_package/helics-cli/examples/pi-exchange$ helics --version
helics, version 0.1.0a
(py3.7-helics-2.6.1) lei@lei-VirtualBox:~/Install_package/helics-cli/examples/pi-exchange$ helics run --path runner.json 
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/bin/helics", line 8, in <module>
    sys.exit(cli())
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/helics_cli/cli.py", line 168, in run
    if config["broker"] is True:
KeyError: 'broker'

Is there anything I forget to do before run it? I just install the helics-cli, and I also cannot run the validation successfully.

kdheepak commented 3 years ago

Can you try the latest main branch?

Screen Shot 2021-05-31 at 9 58 33 AM
kdheepak commented 3 years ago

You'll need to use this to install:

pip install git+git://github.com/GMLC-TDC/helics-cli.git@main
lzheng28 commented 3 years ago

You'll need to use this to install:

pip install git+git://github.com/GMLC-TDC/helics-cli.git@main

Just check it, but it leads to another error

(py3.7-helics-2.6.1) lei@lei-VirtualBox:~/Install_package/helics-cli/examples/pi-exchange$ helics
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/bin/helics", line 5, in <module>
    from helics_cli.cli import cli
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/helics_cli/cli.py", line 18, in <module>
    from . import observer
  File "/home/lei/anaconda3/envs/py3.7-helics-2.6.1/lib/python3.7/site-packages/helics_cli/observer.py", line 23, in <module>
    broker: h.HelicsBroker
AttributeError: module 'helics' has no attribute 'HelicsBroker'

And my helics version is v2.6.1

kdheepak commented 3 years ago

Can you pip uninstall helics and then run pip install helics. You need the one of the pyhelics interfaces instead of the swig interface. You can do pip install helics==2.6.1.post11 if you want HELICS v2.6.1.

See this link for all available releases: https://github.com/GMLC-TDC/pyhelics/releases

lzheng28 commented 3 years ago

Can you pip uninstall helics and then run pip install helics. You need the one of the pyhelics interfaces instead of the swig interface. You can do pip install helics==2.6.1.post11 if you want HELICS v2.6.1.

See this link for all available releases: https://github.com/GMLC-TDC/pyhelics/releases

But in my project(C++), I want to use helics dynamic library to compile it, does it influence my project?

kdheepak commented 3 years ago

It shouldn’t affect. You can use any version. We recommend using the latest since that contains the most bug fixes.

kdheepak commented 3 years ago

With the pyhelics interface, you can also use an environment variable to tell the Python package to use the helics library in a specific local path.

lzheng28 commented 3 years ago

Okay, I'll have a try after my project is done, because I built helics from source code which took me much time, I'm worried different version of helics (I mean build from source code and pip install helics) will lead to unexpected error, thank you so much.

By the way, if I use pip to install helics, how can I run the hello world example in this link https://docs.helics.org/en/latest/introduction/hello-world.html, I mean how I compile C++ files.

Or should I install both of them, but when I need to do cosimulation in my project, can I use C++ library in one federate and use python helics in another federate?

kdheepak commented 3 years ago

When you pip install helics you’ll always get a separate HELICS library which is what is used in Python (this is usually precompiled). Whether or not you use the same library that Python uses to link to your C++ application is up to you. You can also have the pyhelics interface use the same library that your C++ application uses if you want but you can’t do this last thing with the swig interface. Hope that makes sense?

lzheng28 commented 3 years ago

Yes, I will use anaconda to get a new environment to pip install helics, and test it, thank you so much.

lzheng28 commented 3 years ago

When you pip install helics you’ll always get a separate HELICS library which is what is used in Python (this is usually precompiled). Whether or not you use the same library that Python uses to link to your C++ application is up to you. You can also have the pyhelics interface use the same library that your C++ application uses if you want but you can’t do this last thing with the swig interface. Hope that makes sense?

I've created a new environment with anaconda, and then pip install helics, and pip install git+git://github.com/GMLC-TDC/helics-cli.git@main, but the error is still here.

Successfully installed helics-2.7.0.post8
(helics-cli) lei@lei-VirtualBox:~$ helics
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/helics-cli/bin/helics", line 5, in <module>
    from helics_cli.cli import cli
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/site-packages/helics_cli/cli.py", line 18, in <module>
    from . import observer
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/site-packages/helics_cli/observer.py", line 23, in <module>
    broker: h.HelicsBroker
AttributeError: module 'helics' has no attribute 'HelicsBroker'
lzheng28 commented 3 years ago

And there is a strange thing that, I certainly installed helics-2.7.0 in the new anaconda environment.

>>> h.helicsGetVersion()
'2.6.1 (2020-10-15)'
>>> 

I've uninstall helics by "pip uninstall helics" and install it again, but the same thing happened.

kdheepak commented 3 years ago

If you can delete the python folder in your installation from source that’ll do it.

lzheng28 commented 3 years ago

Yes, it works, but there is still an error if I enter the direction I install helics from source, but it will disappear in other directory.

(helics-cli) lei@lei-VirtualBox:~$ pwd
/home/lei
(helics-cli) lei@lei-VirtualBox:~$ helics
Usage: helics [OPTIONS] COMMAND [ARGS]...

  HELICS Runner command line interface

Options:
  --version      Show the version and exit.
  -v, --verbose  [x>=0]
  --help         Show this message and exit.

Commands:
  observe
  run       Run HELICS federation
  server
  setup     Setup HELICS federation
  validate  Validate config.json
(helics-cli) lei@lei-VirtualBox:~$ cd software/
(helics-cli) lei@lei-VirtualBox:~/software$ ls
boost_1_65_0  ga        ga-5.7     helics-2.6.1  openmpi1.8.1  xerces-3.2.3
boost_1_70_0  ga-5.6.1  gridlab-d  openmpi       openmpi4.1.0  zeromq
(helics-cli) lei@lei-VirtualBox:~/software$ helics
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/helics-cli/bin/helics", line 5, in <module>
    from helics_cli.cli import cli
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/site-packages/helics_cli/cli.py", line 18, in <module>
    from . import observer
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/site-packages/helics_cli/observer.py", line 16, in <module>
    file_out = logging.FileHandler("observer.log", mode='w')
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/logging/__init__.py", line 1087, in __init__
    StreamHandler.__init__(self, self._open())
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/logging/__init__.py", line 1116, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/home/lei/software/observer.log'
(helics-cli) lei@lei-VirtualBox:~/software$ 
kdheepak commented 3 years ago

That file handler shouldn’t be created at module import time. I think this is a bug in the cli. If so, I’ll fix it. But also, you don’t seem to have write permissions in the software folder. That’s what is causing this error.

lzheng28 commented 3 years ago

Okay, I got it, but there still another problem.

(helics-cli) lei@lei-VirtualBox:~/Install_package/helics-cli$ helics run --path examples/pi-exchange/runner.json
helics-cli [info]: Running federation: pi-exchange
helics-cli [info]: Running federate pisender1 as a background process
helics-cli [info]: Running federate pisender2 as a background process
helics-cli [info]: Running federate pisender3 as a background process
helics-cli [info]: Running federate pireceiver1 as a background process
helics-cli [info]: Running federate pireceiver2 as a background process
helics-cli [info]: Running federate pireceiver3 as a background process
helics-cli [info]: Running federate observer as a background process
Error: FileNotFoundError: [Errno 2] No such file or directory: './bin/helics': './bin/helics'
lzheng28 commented 3 years ago

And another problem raised when I run the validation

(helics-cli) lei@lei-VirtualBox:~/Install_package/helics-cli$ helics run --path examples/echo-federation/HELICSFederation/config.json
helics-cli [info]: Running federation: HELICSFederation
helics-cli [info]: Running federate Federate1 as a background process
helics-cli [info]: Running federate Federate2 as a background process
helics-cli [info]: Waiting for 2 processes to finish ...
helics-cli [error]: Process Federate1 exited with return code 2
helics-cli [error]: Process Federate2 exited with return code 2
helics-cli [info]: Done.
Error: Process Federate1 has failed, killing other processes
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/site-packages/helics_cli/status_checker.py", line 39, in run
    raise HELICSRuntimeError("Error has occurred")
helics_cli.exceptions.HELICSRuntimeError: Error has occurred
kdheepak commented 3 years ago

I don't understand why it is trying to run the observer for you. Can you share the output of cat examples/pi-exchange/runner.json? Also, I don't understand why it is trying to run ./bin/helics?

lzheng28 commented 3 years ago

Here is the output

(helics-cli) lei@lei-VirtualBox:~/Install_package/helics-cli$ cat examples/pi-exchange/runner.json
{
  "federates": [
    {
      "directory": ".",
      "exec": "python -u pisender.py 1",
      "host": "localhost",
      "name": "pisender1"
    },
    {
      "directory": ".",
      "exec": "python -u pisender.py 2",
      "host": "localhost",
      "name": "pisender2"
    },
    {
      "directory": ".",
      "exec": "python -u pisender.py 3",
      "host": "localhost",
      "name": "pisender3"
    },
    {
      "directory": ".",
      "exec": "python -u pireceiver.py 1",
      "host": "localhost",
      "name": "pireceiver1"
    },
    {
      "directory": ".",
      "exec": "python -u pireceiver.py 2",
      "host": "localhost",
      "name": "pireceiver2"
    },
    {
      "directory": ".",
      "exec": "python -u pireceiver.py 3",
      "host": "localhost",
      "name": "pireceiver3"
    },
    {
      "directory": "../../",
      "exec": "./bin/helics observe --federates 6",
      "host": "localhost",
      "name": "observer"
    }
  ],
  "name": "pi-exchange"
}
(helics-cli) lei@lei-VirtualBox:~/Install_package/helics-cli$ 
kdheepak commented 3 years ago

Remove the last block, i.e.

    {
      "directory": "../../",
      "exec": "./bin/helics observe --federates 6",
      "host": "localhost",
      "name": "observer"
    }

Or use the most recent commit in helics-cli.

lzheng28 commented 3 years ago

Remove the last block, i.e.

    {
      "directory": "../../",
      "exec": "./bin/helics observe --federates 6",
      "host": "localhost",
      "name": "observer"
    }

Or use the most recent commit in helics-cli.

Yes, this works, but the last problem is still here.

(helics-cli) lei@lei-VirtualBox:~/Install_package/helics-cli$ helics run --path examples/echo-federation/HELICSFederation/config.json
helics-cli [info]: Running federation: HELICSFederation
helics-cli [info]: Running federate Federate1 as a background process
helics-cli [info]: Running federate Federate2 as a background process
helics-cli [info]: Waiting for 2 processes to finish ...
helics-cli [error]: Process Federate1 exited with return code 2
helics-cli [error]: Process Federate2 exited with return code 2
helics-cli [info]: Done.
Error: Process Federate1 has failed, killing other processes
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/lei/anaconda3/envs/helics-cli/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/lei/Install_package/helics-cli/helics_cli/status_checker.py", line 39, in run
    raise HELICSRuntimeError("Error has occurred")
helics_cli.exceptions.HELICSRuntimeError: Error has occurred

Please note that the path of the json file is in examples/echo-federation/HELICSFederation/config.json

kdheepak commented 3 years ago

I made some changes that should fix this. You’ll need to update to the latest version of helics-cli. Can you delete the echo-federation folder and try again?

kdheepak commented 3 years ago

This works for me with the latest:

$ helics --version
helics, version 0.5.1

$ helics setup
~/gitrepos/helics-cli/HELICSFederation/config.json

$ helics run --path HELICSFederation/config.json
helics-cli [info]: Running federation: HELICSFederation
helics-cli [info]: Running federate Federate1 as a background process
helics-cli [info]: Running federate Federate2 as a background process
helics-cli [info]: Waiting for 2 processes to finish ...
helics-cli [info]: Done.
lzheng28 commented 3 years ago

Yes, this works for me, but I think you can revise the README.md, so that it will include HELICSFederation in the path.