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

📦️ Fix packaging bugs from #1971 #1981

Merged
merged 15 commits into from
Aug 28, 2023
Merged

📦️ Fix packaging bugs from #1971 #1981

merged 15 commits into from
Aug 28, 2023

Conversation

shnizzedy
Copy link
Member

@shnizzedy shnizzedy commented Aug 11, 2023

Fixes

Fixes #1971 by @shnizzedy
Fixes cmi-cnlSlack/#cpac/p1691439898750679 by @nx10
Fixes cmi-cnlSlack/#cpac/p1691686240018959 by @e-kenneally
Fixes #1983 by @e-kenneally
Restores 42962c1 by @anibalsolon

Description

  • Restores bc to images with FreeSurfer
  • Resets permissions on path for installing Python packages in final image
  • Moves xvfbwrapper from OS base image installation into C-PAC dependencies
  • Adds tests for
    • all of these changes (except xvfbwrapper)
    • availability of all local templates referenced in all preconfigs
  • Updates broken paths to local templates in preconfigs

Technical details

  • Updates the logic for choosing the reference template when resolving an unpacked resolution
    • MNI152_T1_2mm_eye_mask.nii.gz is the only resolution prepackaged here, which was causing a problem if the output resolution wasn't 2mm.
    • some have 0.5mm, why not use those?
  • Adds init files to allow coverage to capture tests
  • Also updates .pylintrc re: several deprecated-option warnings

Tests

bc

@pytest.mark.skipif("FREESURFER_HOME" not in os.environ or
not os.path.exists(os.environ['FREESURFER_HOME']),
reason="We don't need bc if we don't have FreeSurfer.")
def test_bc():
"""Make sure ``bc`` is installed"""
_, exit_code = log_subprocess(['bc', '--version'])
assert exit_code == 0

Coverage for CPAC/surface/tests/test_installation.py: 100%

package installation permissions

def test_import_torch():
"""
Test that ``torch`` successfully imports after being installed dynamically.
This test is necessarily slow because it involves dynamically
installing ``torch``.
"""
# pylint: disable=import-error,unused-import,wrong-import-order
from CPAC import unet
import torch

Coverage for CPAC/unet/tests/test_torch.py: 100%

preconfig templates

@pytest.mark.parametrize('pipeline', ALL_PIPELINE_CONFIGS)
def test_packaged_path_exists(pipeline):
"""
Check that all local templates are included in image at at
least one resolution
"""
rpool = ingress_pipeconfig_paths(Preconfiguration(pipeline),
ResourcePool(), 'pytest')
for resource in rpool.rpool.values():
node = list(resource.values())[0].get('data')[0]
if hasattr(node.inputs, 'template'
) and not node.inputs.template.startswith('s3:'):
if not pipeline == 'rodent' and node.inputs.template.startswith(
'/template/study_based'):
assert (os.path.exists(node.inputs.template) or
get_highest_local_res(node.inputs.template,
node.inputs.resolution).exists())

Additional details

Rodent pipeline

  • I'm not sure if these are intentionally unincluded files that would be named and bound this way
    # Standard Skull Stripped Template. Used as a reference image for functional registration.
    # This can be different than the template used as the reference/fixed for T1-to-template registration.
    T1w_brain_template_funcreg: /template/study_based_functional_template_sk.nii.gz
    # Standard Anatomical Brain Image with Skull.
    # This can be different than the template used as the reference/fixed for T1-to-template registration.
    T1w_template_funcreg: /template/study_based_functional_template.nii.gz
    # Included as part of the 'Image Resource Files' package available on the Install page of the User Guide.
    # It is not necessary to change this path unless you intend to use a non-standard symmetric template.
    T1w_brain_template_symmetric: /template/study_based_functional_template_sk.nii.gz
    # A reference symmetric brain template for resampling
    T1w_brain_template_symmetric_for_resample: /template/study_based_functional_template_sk.nii.gz
    # Included as part of the 'Image Resource Files' package available on the Install page of the User Guide.
    # It is not necessary to change this path unless you intend to use a non-standard symmetric template.
    T1w_template_symmetric: /template/study_based_functional_template.nii.gz
    # A reference symmetric skull template for resampling
    T1w_template_symmetric_for_resample: /template/study_based_functional_template.nii.g
    # Included as part of the 'Image Resource Files' package available on the Install page of the User Guide.
    # It is not necessary to change this path unless you intend to use a non-standard symmetric template.
    dilated_symmetric_brain_mask: /template/study_based_functional_template_mask.nii.gz
    # A reference symmetric brain mask template for resampling
    dilated_symmetric_brain_mask_for_resample: /template/study_based_functional_template_mask.nii.gz
    but they obviously don't exist in the image. I just excluded them from the test here
    if not pipeline == 'rodent' and node.inputs.template.startswith(
    '/template/study_based'):
    but we should either document their intent or clear them out of the preconfig

Updated resolve_resolution

These are both described above, but I want to highlight them to make sure

"""Given a reference template path and a resolution string, get all
resolutions of that template in the same local path and return the
highest resolution.
is an acceptable design choice:

  • MNI152_T1_2mm_eye_mask.nii.gz is the only resolution prepackaged here, which was causing a problem if the output resolution wasn't 2mm.
  • some have 0.5mm, why not use those?
  • I specifically excluded checking the s3 templates
    ) and not node.inputs.template.startswith('s3:'):
    but if we want to test those I think we could update
    def get_highest_local_res(template: Union[Path, str], tagname: str) -> Path:
    to do an aws s3 ls for s3 files so we wouldn't have to download (and potentially resample) each one

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I updated the changelog.
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@shnizzedy
Copy link
Member Author

I see there are merge conflicts. I'll fix those next week

@shnizzedy shnizzedy requested a review from a team August 28, 2023 14:18
@shnizzedy shnizzedy merged commit ae44d32 into develop Aug 28, 2023
@shnizzedy shnizzedy deleted the restore/bc branch August 28, 2023 15:01
@shnizzedy shnizzedy mentioned this pull request Sep 26, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants