No problem, mate, I know myself how confusing the setup can be. Could you maybe answer the following question so that we can find the best way to help you?
Does import dolfin on your computer work? I mean outside of docker, on your Windows machine, in a regular python shell. Further does any of import fencisx or dolfinx work?
Your main goal is to get the code from the paper running, correct? I took a quick look at the paper but couldn’t find out what version of fenics they are using, do you maybe know more?
What does pip show fenics say? Which version is installed?
Keep in mind that fenics and fenicsx are two completely different beasts. Even the different fenics versions may differ widely.
In my experience, there are these ways to get fenics running:
Use docker (because inside of docker everything is installed and just works).
Yes. The corresponding script in github was last changed 12 months ago. Regarding fenics · PyPI this would mean they (maybe) used version 2019.1.0 (couldn’t find a proper release history from the official fenics homepage)
I have fenics version 2019.1.0 (in accordance to pypi) installed
Solutions:
The docker seems to work as described by dokken but I do not understand how to work independently (call my own functions, plot results, etc.)
Only pip install fenics did not prompt an error but still not working (as you just mentioned it’s more or less a dummy package)
Okay, I really don’t know why your pip-installation doesn’t work, but at some point I just gave up the setup with pip.
To the methods:
See below
It’ll stay a mystery
Install miniconda or anaconda on your system and follow the setup instructions. After that, install fenics via conda using conda install -c conda-forge fenics. It’s worth a try if you’re willing to ‘waste’ some space on your hard drive.
Look, I enjoy pain just as every other masochist out there, but even I wouldn’t want to try to compile fenics on Windows.
Docker:
Did you read dokken’s links? They should basically cover everything you need. Short version: Every docker container is like a little, isolated mini-os, with it’s own file system and programs. If you want your container to be able to communicate with the outside world, you need to tell this docker.
I suggest that before you start with the fancy stuff, try to mount a path into your container. Create somewhere a directory on your Windows machine (e.g. C:\Users\Oskar\fenics or whatever Windows uses as home directories). Find some directory in the container, which already exists (for example the demo-directory), but get the whole path (i.e. without the ~, but /the/absolute/path/to/demo). Then start the container via docker run --rm -it -v C:\Users\Oskar\fenics:/the/absolute/path/to/demo quay.io/fenicsproject/stable:latest. This way, every file you copy into C:\Users\Oskar\fenics will be visible in your container.
Ok, thank’s for letting me know the installation is generally really hard. At least now I know I’m just regular incompetent and not really incompetent.
Seems like 2. and 4. shouldn’t be investigated any further for now. Unfortunately 3. using miniconda prompts the following:
(base) C:\Users\neuma>conda install -c conda-forge fenics
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- fenics
Current channels:
- https://conda.anaconda.org/conda-forge/win-64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
So going with the Docker Method I try to mount a local directory into my container with
C:\Users\neuma>docker run --rm -it -v C:\Users\neuma\fenics:C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
or
C:\Users\neuma>docker run --rm -it -v C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
or using dokken’s link
C:\Users\neuma>docker run --rm -it -v %cd%:C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
or
C:\Users\neuma>docker run --rm -it -v %cd%:C:\Users\neuma\fenics
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
which doesn’t work. Do you know what I’m doing wrong? My understanding is that I only want to launch a docker inside a specific directory that contains pyhton files?! Unfortunately the before mentioned example code is used from an online repository Quay and not started from a local folder.
Concerning this line from dokken, I’ve tried including to the best of my understanding the information here Explore networking features | Docker Documentation to do Port Mapping (again, I don’t really now what this means, apart from sending info to an URL) via the following modification:
Instead of
docker run -ti quay.io/fenicsproject/stable:latest
I use
docker run -p 80:80 -ti quay.io/fenicsproject/stable:latest
or docker run -p 8000:80 -ti quay.io/fenicsproject/stable:latest
as recommended which also doesn’t do the trick of letting me see the visualization of the results of demo_poisson.py in a webbrowser nor leads me any further to how to run my own scripts in a local directory. I’m pretty lost on that one to be honest…
No, I don’t understand what -v means. I’m pretty new to docker and I hoped I could just find a procedur to execute scripts and avoid getting deeper into docker itself.
I’ve tried the following in Windows PowerShell (run as admin):
PS C:\Windows\system32> docker run -ti -v $(PWD):/home/shared quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Windows\system32> docker run -ti -v $(PWD): C:/Users/neuma/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Windows\system32> docker run -ti -v $(PWD): C:/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
Also I tried the normal Windows Terminal and got this:
C:\Users\neuma>docker run -ti -v $(PWD):/home/shared quay.io/fenicsproject/stable:latest
docker: Error response from daemon: create $(PWD): "$(PWD)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
C:\Users\neuma>docker run -ti -v $(PWD): C:/Users/neuma/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.
C:\Users\neuma>docker run -ti -v $(PWD): C:/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
(I did create the fenics directories in the corresponding paths).
Your line was always the first I did try out (using power shell or terminal). So the first line of the quoted code of my last post was showing the results of runing the command you suggested.
@Oskar in all your four examples in your first answer you forgot to specifiy the container you want to start, i.e. you forgot the quay.io/fenicsproject/stable:latest at the end of the command.
And I wouldn’t try to dig deeper into conda, maybe the packages are just no available for Windows or so.
Edit: I just noticed that /home/shared doesn’t exist per default in the quay-container? Isn’t that a problem? If so, maybe try /home/fenics instead.
$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
[OPTIONS] → -ti and -v
IMAGE[:TAG|@DIGEST] is the container including all sorts of executables like the fenics/dolfin libraries?! In my example IMAGE would then be quay.io/fenicsproject/stable:latest (do not know what is meant by TAG and DIGEST)?
[COMMAND] → ?
[ARG...] → my local directory ?
Just to lift the fog on what is actually going on.
Edit: The following was example 2/4 of the previous post with adding http://quay.io/fenicsproject/stable:latest at the end. This does not create an error instantly but it seems to do the same like the example script:
PS C:\Users\neuma> docker run --rm -it -v C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py quay.io/fenicsproject/stable:latest
# FEniCS stable version image
Welcome to FEniCS/stable!
This image provides a full-featured and optimized build of the stable
release of FEniCS.
To help you get started this image contains a number of demo
programs. Explore the demos by entering the 'demo' directory, for
example:
cd ~/demo/python/documented/poisson
python3 demo_poisson.py
fenics@7d49effa0788:~$ cd C:/Users/neuma/fenics/hybrid-fem-nn-examples-main/examples/pinn_linear
bash: cd: C:/Users/neuma/fenics/hybrid-fem-nn-examples-main/examples/pinn_linear: No such file or directory
fenics@7d49effa0788:~$ main.py
bash: main.py: command not found
Again I can’t navigate to the directory of interest or run the code.
That’s wild. Just to double check, docker run -ti quay.io/fenicsproject/stable:latest does work?
Afaik you can’t mount a single file via -v. Further, inside your container you have to use linux commands. That is, show the current files with ls, change directories with cd and specifiy paths via /this/scheme/, and not windows-like (with C:\...)
PS C:\Users\neuma> docker run -ti quay.io/fenicsproject/stable:latest
# FEniCS stable version image
Welcome to FEniCS/stable!
This image provides a full-featured and optimized build of the stable
release of FEniCS.
To help you get started this image contains a number of demo
programs. Explore the demos by entering the 'demo' directory, for
example:
cd ~/demo/python/documented/poisson
python3 demo_poisson.py
fenics@3872e8ecbbd2:~$
I would be also ok with mounting a directory which contains python scripts and which I can execute via power shell and plot via browser (or whatever). I’ve tried to follow the linux syntax but couldn’t change to any local directory.
Ok, so from the double check I assume that there is some problem with the mounting of the directories. I’m really just guessing right now, but could you maybe try out docker run -ti -v "C:\\Users\\neuma\\fenics":/home/fenics quay.io/fenicsproject/stable:latest
that is, with double backslashes?
And if that doesn’t work, could you please create an empty directory (e.g. C:\Users\neuma\fenics\testdir) and try it again with this directory? Once with normal backslashes, once with double backslashes?
Again, if you want to change a directory on linux, you have to use the linux syntax. cd /home, for examples, changes in to the folder /home. With cd .. you go up. There is no C:\whatever on linux. The filesystem root starts with /.
PS C:\Users\neuma> docker run -ti -v "C:\\Users\\neuma\\fenics":/home/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Users\neuma> docker run -ti -v "C:\\Users\\neuma\\fenics\\testdir":/home/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Users\neuma> docker run -ti -v "C:\Users\neuma\fenics\testdir":/home/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
Ok got it. So what is the counterpart to my actual system directory structure on windows when I’m working on the Linux distribution via docker? Say I have a file C:\Users\neuma\fenics\script.py, where would it live in the Linux world of /home/whatever/whatever?
Hmm, just to make sure: Have you tried it without the quotation marks? docker run -ti -v C:\Users\neuma\fenics\testdir:/home/fenics quay.io/fenicsproject/stable:latest
Maybe start with this one and if it doesn’t work, try with double backslashes and then without testdir?^^
The Linux file system structure differs fundamentally from Windows. On Windows, if you have for example three devices/partitions, each of them gets a letter and has its own root (C:\..., D:\..., E:\...).
On Linux, however, one ‘abstract’ virtual root is created (/) and the devices are mounted into whatever directory you want them to be mounted. For example, you could decide to mount your first hard drive to /home, your second to /usr and your third to /opt/games/saves.
In general, your home directory would be located at /home/neuma if you were using a Linux system. In docker, however, there is no directory for you or your user account. In the fenics-container, there is only /home/fenics, which is also the location where you ‘spawn’ when you start the container. It is marked by the little ~. You can go up via cd .. and the tilde should be replaced by /home. Then, typing ls should list the only directory, fenics.
PS C:\Users\neuma> docker run -ti -v C:\\Users\\neuma\\fenics:/home/fenics quay.io/fenicsproject/stable:latest
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
fenics@eb77502101a4:~$ exit
exit
PS C:\Users\neuma> docker run -ti -v C:\\Users\\neuma\\fenics\\testdir:/home/fenics quay.io/fenicsproject/stable:lates
Unable to find image 'quay.io/fenicsproject/stable:lates' locally
docker: Error response from daemon: manifest for quay.io/fenicsproject/stable:lates not found: manifest unknown: manifest unknown.
See 'docker run --help'.
PS C:\Users\neuma> docker run -ti -v C:\Users\neuma\fenics\testdir:/home/fenics quay.io/fenicsproject/stable:latest
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Number one and two seem to ‘work’. If I do ls after the last try I get only the folder shared:
fenics@15c70481b35a:~$ ls
shared
Still the big question: How can I run and see my own scripts? Is there maybe a way just to write python code in the power shell?
That’s good! Ok, could you now please just run of them (preferably the working version with testdir), and then keep the shell opened? That is, don’t type exit, just let it run. While the shell with docker is running, could you check the C:\Users\neuma\fenics\testdir-directory on your Windows system (via file explorer) if any new files appeared?
One additional question, out of curiosity (and because it’s maybe a little bit easier), does this one work? docker run -ti -v C:/Users/neuma/fenics/testdir:/home/fenics quay.io/fenicsproject/stable:latest