Skip to content

PyPulseq 1.5.0 compatibility #166

@schuenke

Description

@schuenke

Hey,

we realized that you limited mrzero to PyPulseq < 1.5.0 again in aca0f6a

This leads to failing workflows for https://github.com/PTB-MR/mrseq because the PyPulseq 1.4.2.post1 release is missing a lot of bug fixes and features.

For us, mrzero in combination with PyPulseq 1.5.0 worked perfectly fine as long as we create sequences using the v141 compatibility mode. In MRseq, we use a write_sequence helper function that ensures compatibility with older and newer PyPulseq versions:

def _parse_version_tuple(v: str) -> tuple[int, ...]:
    """Parse a version string into a tuple of integers."""
    v = v.split('+', 1)[0]
    v = v.split('-', 1)[0]
    parts: list[int] = []
    for token in v.split('.'):
        if token.isdigit():
            parts.append(int(token))
        else:
            digits = ''.join(ch for ch in token if ch.isdigit())
            parts.append(int(digits) if digits else 0)
    return tuple(parts)


def _pypulseq_version_tuple() -> tuple[int, ...]:
    """Return the version of PyPulseq as a tuple of integers."""
    try:
        return _parse_version_tuple(version('pypulseq'))
    except PackageNotFoundError:
        return (0,)


def write_sequence(
    seq: pp.Sequence,
    filename: str,
    create_signature: bool = True,
    v141_compatibility: bool = True,
    **kwargs,
):
    """Write a PyPulseq sequence to a *.seq file.

    Parameters
    ----------
    seq
        PyPulseq sequence object
    filename
        Name of the *.seq file
    create_signature
        Whether to create a signature in the *.seq file
    v141_compatibility
        Whether to use v1.4.1 compatibility mode
    **kwargs
        Additional keyword arguments passed to the PyPulseq write function
    """
    pypulseq_version = _pypulseq_version_tuple()
    if pypulseq_version >= (1, 5, 0):
        return seq.write(filename, create_signature=create_signature, v141_compat=v141_compatibility, **kwargs)
    return seq.write(filename, create_signature=create_signature, **kwargs)

and then we use it in our sequence scripts to save the seq-files like in this example:

write_sequence(seq, <name>, create_signature=True, v141_compatibility=True)

Would this be an option for you to use something similar in your example scripts?
I would like to avoid pinning mrzero to one of the previous releases where you already successfully realized the PyPulseq 1.5.0 support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions