Skip to content

Commit

Permalink
Merge pull request #189 from dcmonroe/main
Browse files Browse the repository at this point in the history
Update happy.py | mem check for singularity containers
  • Loading branch information
bbfrederick authored Dec 30, 2024
2 parents 08eb4f7 + a2d098d commit 54dc9f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Release history

## Version 3.0alpha2 (12/20/24)
* (package) Now includes codespell checking thank you to Yaroslav O. Halchenko (yarikoptic)!
## Version 3.0alpha2 (12/30/24)
* (happy, rapidtide) Now do more sophisticated container checking to handle both Docker and Singularity. Thank you to Derek Monroe (https://github.com/dcmonroe) for the catch and the fix!
* (package) Now includes codespell checking thanks to Yaroslav O. Halchenko (https://github.com/yarikoptic)!

## Version 3.0alpha1 (12/20/24)
* (rapidtide) The ``--fixdelay`` option has been split into two options. ``--initialdelay DELAY`` lets you specify either a float that sets the starting delay for every voxel to that value, or a 3D file specifying the initial delay for each voxel. ``--nodelayfit`` determines whether the delay can be adjusted from its initial value. Closes https://github.com/bbfrederick/rapidtide/issues/171. KNOWN ISSUE: If you supply an initial delay map, instead of using the global mean, rapidtide should use the delays to make your first stage regressor. Currently that is not the case.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ authors = [
{name = "Daniel M. Drucker, Ph.D."},
{name = "Jeffrey N Stout"},
{name = "Yaroslav O. Halchenko"},
{name = "Derek Monroe"},
]

[project.urls]
Expand Down
18 changes: 18 additions & 0 deletions rapidtide/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ def findavailablemem():
return free, swap


def checkifincontainer():
# Determine if the program is running in a container. If so, we may need to adjust the python memory
# limits because they are not set properly. But check if we're running on CircleCI - it does not seem
# to like you twiddling with the container parameters.
#
# possible return values are: None, "Docker", "Singularity", and "CircleCI"
#
if os.environ.get("SINGULARITY_CONTAINER") is not None:
containertype = "Singularity"
elif os.environ.get("RUNNING_IN_CONTAINER") is not None:
containertype = "Docker"
else:
containertype = None
if os.environ.get("CIRCLECI") is not None:
containertype = "CircleCI"
return containertype


def setmemlimit(memlimit):
resource.setrlimit(resource.RLIMIT_AS, (memlimit, memlimit))

Expand Down
19 changes: 10 additions & 9 deletions rapidtide/workflows/happy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ def happy_main(argparsingfunc):
# create the canary file
Path(f"{outputroot}_ISRUNNING.txt").touch()

# if we are running in a container, make sure we enforce memory limits properly
try:
testval = os.environ["RUNNING_IN_CONTAINER"]
except KeyError:
args.runningincontainer = False
else:
args.runningincontainer = True
args.containermemfree, args.containermemswap = tide_util.findavailablemem()
tide_util.setmemlimit(args.containermemfree)
# if running in Docker or Apptainer/Singularity, this is necessary to enforce memory limits properly
# otherwise likely to error out in gzip.py or at voxelnormalize step. But do nothing if running in CircleCI
# because it does NOT like you messing with the container.
args.containertype = tide_util.checkifincontainer()
if args.containertype is not None:
if args.containertype != "CircleCI":
args.containermemfree, args.containermemswap = tide_util.findavailablemem()
tide_util.setmemlimit(args.containermemfree)
else:
print("running in CircleCI environment - not messing with memory")

# Set up loggers for workflow
setup_logger(
Expand Down
18 changes: 11 additions & 7 deletions rapidtide/workflows/rapidtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,18 @@ def rapidtide_main(argparsingfunc):
gc.enable()
print("turning on garbage collection")

# if we are running in a container, make sure we enforce memory limits properly
if "RUNNING_IN_CONTAINER" in os.environ:
optiondict["runningincontainer"] = True
optiondict["containermemfree"], optiondict["containermemswap"] = tide_util.findavailablemem()
if optiondict["containermemfix"]:
# if running in Docker or Apptainer/Singularity, this is necessary to enforce memory limits properly
# otherwise likely to error out in gzip.py or at voxelnormalize step. But do nothing if running in CircleCI
# because it does NOT like you messing with the container.
optiondict["containertype"] = tide_util.checkifincontainer()
if optiondict["containertype"] is not None:
if optiondict["containertype"] != "CircleCI":
optiondict["containermemfree"], optiondict["containermemswap"] = (
tide_util.findavailablemem()
)
tide_util.setmemlimit(optiondict["containermemfree"])
else:
optiondict["runningincontainer"] = False
else:
print("running in CircleCI environment - not messing with memory")

# write out the current version of the run options
optiondict["currentstage"] = "init"
Expand Down

0 comments on commit 54dc9f4

Please sign in to comment.