pyems icon indicating copy to clipboard operation
pyems copied to clipboard

Installation of openems and csxcad python interfaces

Open drandyhaas opened this issue 2 years ago • 9 comments

Hi, I'm excited about this project, if it really will allow free PCB FDTD EM simulation! I don't understand how to install the python dependencies required. Is this expected to work on Windows, or only in Linux? Or only Ubuntu? It would be great to specify exactly how to install the needed dependencies (and on what platform), and install pyems, in order to get up and running. Thanks!

drandyhaas avatar Jan 14 '22 14:01 drandyhaas

The installation for pyems itself should be fairly straightforward. However, installing openems is non-trivial. Have you taken a look at the installation instructions for that? You'll also need the python bindings. If you run into any trouble I would check out the openems forum. I can think about improving the installation instructions for pyems, but this may end up just being links to openems's instructions, since I don't want to duplicate the information already presented there.

This has only been tested on Linux and should work on any distribution, though I've only tested it on Ubuntu and Nix. If you want to use nix (you can use the package manager standalone without the distribution if you want), the installation should be trivial as I've already done the work of packaging up everything. I can provide more details if you're interested.

I'd like this to work on Windows (and I can't think of any fundamental reason why it shouldn't work, since openems supports it), but I don't use Windows myself and don't have the time to do extensive development for that. But, I would accept bug reports for Windows incompatibilities. I think it should be fairly simple to make pyems Windows-compatible.

matthuszagh avatar Jan 14 '22 15:01 matthuszagh

I have a openems installation in windows under conda environment. However, I tried pyems installation by pip, conda and python setup. In all cases, I endup with either simulation package not found or some other package not found error. Any indication of what is going wrong will be helpful.

MukherjeeManas avatar May 11 '23 05:05 MukherjeeManas

Can you provide me with more detail about the commands you're running and the error messages you get?

matthuszagh avatar May 11 '23 05:05 matthuszagh

I'm using the coax example as a test. The output error in jupyter I'm getting is

C:\Users\cqtmukhe\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\mesh.py:664: UserWarning: Mesh line at pos -2.5676 for dimension 1 violates smoothness. Smoothness was set to 1.50 but this line creates a spacing with factor 1.86. For convenience the last three lines are: -2.6076, -2.5816 and -2.5676.
C:\Users\cqtmukhe\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\mesh.py:664: UserWarning: Mesh line at pos 2.6076 for dimension 1 violates smoothness. Smoothness was set to 1.50 but this line creates a spacing with factor 1.86. For convenience the last three lines are: 2.5676, 2.5816 and 2.6076.
C:\Users\cqtmukhe\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\mesh.py:664: UserWarning: Mesh line at pos -2.5676 for dimension 2 violates smoothness. Smoothness was set to 1.50 but this line creates a spacing with factor 1.86. For convenience the last three lines are: -2.6076, -2.5816 and -2.5676.
C:\Users\cqtmukhe\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\mesh.py:664: UserWarning: Mesh line at pos 2.6076 for dimension 2 violates smoothness. Smoothness was set to 1.50 but this line creates a spacing with factor 1.86. For convenience the last three lines are: 2.5676, 2.5816 and 2.6076.
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[1], line 67
     64 if os.getenv("_PYEMS_PYTEST"):
     65     sys.exit(0)
---> 67 sim.run()
     68 sim.view_field()
     70 z0 = sim.ports[0].impedance()

File ~\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\simulation.py:173, in Simulation.run(self, csx, debug_pec, threads)
    157 """
    158 Run simulation.
    159 
   (...)
    170     other number uses the number provided.
    171 """
    172 if csx:
--> 173     self.view_csx(prompt=True)
    174 if not self._calc_only:
    175     if debug_pec:

File ~\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\simulation.py:192, in Simulation.view_csx(self, prompt)
    186 def view_csx(self, prompt: bool = False) -> None:
    187     """
    188     View the CSX network.
    189 
    190     :param prompt: Prompt user whether to continue simulation.
    191     """
--> 192     subprocess.run(["AppCSXCAD", self._csx_path])
    193     if prompt:
    194         self._prompt_terminate()

File ~\.conda\envs\Py10_env\Lib\subprocess.py:548, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    545     kwargs['stdout'] = PIPE
    546     kwargs['stderr'] = PIPE
--> 548 with Popen(*popenargs, **kwargs) as process:
    549     try:
    550         stdout, stderr = process.communicate(input, timeout=timeout)

File ~\.conda\envs\Py10_env\Lib\subprocess.py:1024, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
   1020         if self.text_mode:
   1021             self.stderr = io.TextIOWrapper(self.stderr,
   1022                     encoding=encoding, errors=errors)
-> 1024     self._execute_child(args, executable, preexec_fn, close_fds,
   1025                         pass_fds, cwd, env,
   1026                         startupinfo, creationflags, shell,
   1027                         p2cread, p2cwrite,
   1028                         c2pread, c2pwrite,
   1029                         errread, errwrite,
   1030                         restore_signals,
   1031                         gid, gids, uid, umask,
   1032                         start_new_session, process_group)
   1033 except:
   1034     # Cleanup if the child failed starting.
   1035     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~\.conda\envs\Py10_env\Lib\subprocess.py:1509, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)
   1507 # Start the process
   1508 try:
-> 1509     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1510                              # no special security
   1511                              None, None,
   1512                              int(not close_fds),
   1513                              creationflags,
   1514                              env,
   1515                              cwd,
   1516                              startupinfo)
   1517 finally:
   1518     # Child is launched. Close the parent's copy of those pipe
   1519     # handles that only the child should have open.  You need
   (...)
   1522     # pipe will not close when the child process exits and the
   1523     # ReadFile will hang.
   1524     self._close_pipe_fds(p2cread, p2cwrite,
   1525                          c2pread, c2pwrite,
   1526                          errread, errwrite)

FileNotFoundError: [WinError 2] The system cannot find the file specified

MukherjeeManas avatar May 11 '23 05:05 MukherjeeManas

Is AppCSXCAD in your path? Try executing that on it's own. Otherwise, I wonder if this line is an issue since it uses a forward slash in the path.

matthuszagh avatar May 12 '23 04:05 matthuszagh

Yes AppCSXCAD is in the path as I'm running the openEMS with it native python without any problem. If the forward slash is a problem, what do I need to do?

MukherjeeManas avatar May 15 '23 02:05 MukherjeeManas

Try https://github.com/matthuszagh/pyems/pull/63.

matthuszagh avatar May 15 '23 18:05 matthuszagh

Thanks for the update, however I still have the problem. Now, I'm doubtful if the appCXSCAD is installed properly. I followed the instruction as in https://docs.openems.de/python/install.html#windows

Do I need to separately install appCSXCAD?

The error I'm getting is

FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 67
     64 if os.getenv("_PYEMS_PYTEST"):
     65     sys.exit(0)
---> 67 sim.run()
     68 sim.view_field()
     70 z0 = sim.ports[0].impedance()

File ~\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\simulation.py:173, in Simulation.run(self, csx, debug_pec, threads)
    157 """
    158 Run simulation.
    159 
   (...)
    170     other number uses the number provided.
    171 """
    172 if csx:
--> 173     self.view_csx(prompt=True)
    174 if not self._calc_only:
    175     if debug_pec:

File ~\.conda\envs\Py10_env\Lib\site-packages\pyems-0.1.0-py3.11.egg\pyems\simulation.py:192, in Simulation.view_csx(self, prompt)
    186 def view_csx(self, prompt: bool = False) -> None:
    187     """
    188     View the CSX network.
    189 
    190     :param prompt: Prompt user whether to continue simulation.
    191     """
--> 192     subprocess.run(["AppCSXCAD", self._csx_path])
    193     if prompt:
    194         self._prompt_terminate()

File ~\.conda\envs\Py10_env\Lib\subprocess.py:548, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    545     kwargs['stdout'] = PIPE
    546     kwargs['stderr'] = PIPE
--> 548 with Popen(*popenargs, **kwargs) as process:
    549     try:
    550         stdout, stderr = process.communicate(input, timeout=timeout)

File ~\.conda\envs\Py10_env\Lib\subprocess.py:1024, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
   1020         if self.text_mode:
   1021             self.stderr = io.TextIOWrapper(self.stderr,
   1022                     encoding=encoding, errors=errors)
-> 1024     self._execute_child(args, executable, preexec_fn, close_fds,
   1025                         pass_fds, cwd, env,
   1026                         startupinfo, creationflags, shell,
   1027                         p2cread, p2cwrite,
   1028                         c2pread, c2pwrite,
   1029                         errread, errwrite,
   1030                         restore_signals,
   1031                         gid, gids, uid, umask,
   1032                         start_new_session, process_group)
   1033 except:
   1034     # Cleanup if the child failed starting.
   1035     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~\.conda\envs\Py10_env\Lib\subprocess.py:1509, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)
   1507 # Start the process
   1508 try:
-> 1509     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1510                              # no special security
   1511                              None, None,
   1512                              int(not close_fds),
   1513                              creationflags,
   1514                              env,
   1515                              cwd,
   1516                              startupinfo)
   1517 finally:
   1518     # Child is launched. Close the parent's copy of those pipe
   1519     # handles that only the child should have open.  You need
   (...)
   1522     # pipe will not close when the child process exits and the
   1523     # ReadFile will hang.
   1524     self._close_pipe_fds(p2cread, p2cwrite,
   1525                          c2pread, c2pwrite,
   1526                          errread, errwrite)

FileNotFoundError: [WinError 2] The system cannot find the file specified

MukherjeeManas avatar May 18 '23 13:05 MukherjeeManas

AppCSXCAD is an executable and it needs to be in your path. Try opening a shell and running it on its own (this is what I said in my first message). If your system says the executable can't be found, then it's not installed properly.

As to whether that installation procedure includes AppCSXCAD - I don't know. It's been quite a few years since I performed the installation, and I've never done it for Windows.

matthuszagh avatar May 18 '23 15:05 matthuszagh