Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add package for swak4foam (SWiss Army Knife for Foam) #3650

Closed
wants to merge 1 commit into from

Conversation

olesenm
Copy link
Contributor

@olesenm olesenm commented Mar 31, 2017

  • builds against all 'openfoam' providers

# This file is not part of OpenFOAM, nor does it constitute a component of an
# OpenFOAM distribution.
#
##############################################################################
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably leave this copyright alone. LLNL has some requirement that every python file in Spack has the same license.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss the background by email, when you have some time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @tgamblin approves then I'm okay with it.

return join_path(foam_spec.prefix, d)

raise RuntimeError('No OpenFOAM project directory found')
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier to set this in the openfoam providers. This would look like:

def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
    spack_env.set('WM_PROJECT_DIR', join_path(self.prefix, 'etc', 'bashrc'))

You can do this for as many variables as you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this return statement is redundant.

Copy link
Contributor Author

@olesenm olesenm Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I set this in the provider, where do these land? If the package is physically installed, I guess that they get buried in the .spack directory. But how would something like swak4foam get at these values? (I'm just starting with spack).

Q: is there a spack variable for dirname(self.prefix)? I'm using this in a few places and there must be something better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set this in the provider, that environment variable is set in Spack's environment whenever you build things that depend on it. You can also set run_env if you'd rather have it end up in the module file.

What do you mean by dirname(self.prefix)? The directory above the installation prefix? Why would you want that? If you want the installation directory of a dependency, use self.spec['openfoam'].prefix.


variant('python', default=True, description='Build python modules')

depends_on('openfoam+sources')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source, not sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

# Force python to be found first
PATH=$python_bin:$PATH
#
""".format(python_bin=spec['python'].prefix.bin))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work, some of the time. See #3367. I'm fine with this going in as is, but after #3367 is merged we'll want to change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly looks and feels like a hack, just like the things with bison...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, bison is fine. Python is commonly added as an external package. The problem with Python is that even if Python is installed in /usr/local/bin, the prefix may not be /usr/local. For Homebrew and macOS Python installations, the binary is symlinked to /usr/local/bin but the installation prefix is completely different. We could ask users to set the "real" prefix, but no one will know where to look or want to do that. Sometimes things need to "just work", which is what #3367 is for. Bison doesn't have this problem because it should always be located in spec['bison'].prefix.bin.


# Record the spack spec information
with open("log.spack-spec", 'w') as outfile:
outfile.write(spec.tree())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually need this information for anything? This is already recorded in <prefix>/.spack/spec.yaml.

outfile.write(spec.tree())

# Emit openfoam version
tty.info('Build for {0}'.format(spec['openfoam'].format('$_$@$%@+$+')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already printed when you install the package? No other package prints this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a comment - basically want to know immediately which openfoam version is being pulled or will be built without waiting on it.


def install(self, spec, prefix):
"""Install under the projectdir (== prefix)"""
self.build(spec, prefix) # Should be a separate phase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it a separate phase by adding:

phases = ['build', 'install']

above. Then this line will no longer be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the openfoam packages I tried the same (its in the comments).
If I ran spack install, I could see that it was running through all the phases properly. However, if I tried spack build, it complained about it not having a build phase separate from the install phase.
Now that openfoam-com has been merged, may be you could see if you encounter the same problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I noticed the same problem. See #3642.

args = []
if self.parallel: # Build in parallel? - pass via the environment
os.environ['WM_NCOMPPROCS'] = str(self.make_jobs) \
if self.make_jobs else str(multiprocessing.cpu_count())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use str(make_jobs). Otherwise, users won't be able to change the number of jobs they want with spack install -j <num>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you mentioned this before, but if I stringify self.make_jobs it can be either "None" or "". Both are really bad for WM_NCOMPROCS, which should either be unset (make in parallel) or have an integer number for a parallel build. There is no convenient 'everything' setting.
The code snippets:

if [ -n "$WM_NCOMPPROCS" ]  ...
if [ "$WM_NCOMPPROCS" -gt 1 -a -z "$MAKEFLAGS" ] ... 
parOpt="-j $WM_NCOMPPROCS"  ...

However, if I do request spack install -j 3 swak4foam, it seems to be doing exactly the right thing and only using 3 procs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think self.make_jobs can be none if parallel == True, but I could be wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use self.make_jobs. Just use make_jobs. It's in global scope and set up in set_module_variables_for_package in build_environment. It's always a number (e.g., 1 if not parallel). I think we could better document this, or have a namespace where all this stuff comes in, instead of the module magic.

"spack-build.out", "log.spack-spec",
self.config_file,
'COPYING',
]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in <prefix>/.spack/.

@olesenm olesenm force-pushed the swak4foam branch 2 times, most recently from 260fd30 to bf4139c Compare March 31, 2017 18:05
branch='branches/develop',
git='https://github.com/Unofficial-Extend-Project-Mirror/openfoam-extend-swak4Foam-dev.git') # noqa
# The git mirror can be more convenient than using hg
# http://hg.code.sf.net/p/openfoam-extend/swak4Foam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is more convenient about it? Spack also has Mercurial support that works similarly to our git fetching.

Copy link
Member

@tgamblin tgamblin Apr 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only thing I can think is that Spack's git support does shallow clones and is pretty intensely optimized, while Spack's hg is not...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, shallow clone and with git 'branch' I have a fair better idea of what I am getting. With hg, I'm also totally illiterate and can't make any upstream adjustments without creating complete chaos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment in code

# Force python to be found first
PATH=$python_bin:$PATH
#
""".format(python_bin=spec['python'].prefix.bin))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, bison is fine. Python is commonly added as an external package. The problem with Python is that even if Python is installed in /usr/local/bin, the prefix may not be /usr/local. For Homebrew and macOS Python installations, the binary is symlinked to /usr/local/bin but the installation prefix is completely different. We could ask users to set the "real" prefix, but no one will know where to look or want to do that. Sometimes things need to "just work", which is what #3367 is for. Bison doesn't have this problem because it should always be located in spec['bison'].prefix.bin.

# Emit openfoam version prior to build
# We may be resolved the wrong version, and don't wish to build
# it as a dependency
tty.info('Build for {0}'.format(spec['openfoam'].format('$_$@$%@+$+')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think this is the right thing to do. This could be said about every package in Spack. Spack already tells you what it is going to install before it installs it. If you think we could do a better job of this, we should do it for every package, not just this one.

Copy link
Contributor Author

@olesenm olesenm Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this depends on the size of the underlying package. If I accidentally build the incorrect OpenFOAM version/variant (eg, wrong float size, etc), I've wasted 15-20 min on 24 cpus. Emitting a single line seems to be a small overhead to avoid these types of mistakes.

version(
'dev',
branch='branches/develop',
git='https://github.com/Unofficial-Extend-Project-Mirror/openfoam-extend-swak4Foam-dev.git') # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't need the noqa -- we exempt URLs.

@olesenm olesenm force-pushed the swak4foam branch 3 times, most recently from 9948fda to 2441049 Compare April 6, 2017 08:27
@olesenm
Copy link
Contributor Author

olesenm commented Apr 6, 2017

updated to work with changed openfoam environment

Copy link
Member

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment, otherwise looks good.

import os


class OfSwak4foam(Package):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of renaming this package to be swak4foam instead of of-swak4foam. When someone searches for it in Spack, I think they are more likely to look for swak4foam.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I could go either way. I figured that the of- prefix would make for nice sorting and collation of openfoam-related work, but going for the original name also makes sense.

I'll rejig in the next days (maybe next week) and ping you when it's ready.

@adamjstewart
Copy link
Member

@olesenm Sorry I haven't looked at this PR in a while. I'm on spring break this week so if you have time I would love to get this package in.

@alalazo alalazo requested a review from nrichart March 23, 2018 08:06
@olesenm olesenm closed this Jun 28, 2018
@olesenm olesenm deleted the swak4foam branch June 28, 2018 08:01
@olesenm olesenm restored the swak4foam branch June 28, 2018 08:01
@samcom12
Copy link

Any update on this?

@olesenm
Copy link
Contributor Author

olesenm commented Jan 14, 2022

Any update on this?

I was surprised to see that there might actually be any further interest in this. Feel free to pick up and add updated swak versions. Optionally, if there are particular swak-type of functionality needed in OpenFOAM, I would tend to place more effort there. In the years since this original changeset, openfoam has added a number of expression handling very similar to swak, but based on ragel (for lexing) and lemon (for the parser).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants