{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Running pyAFQ using the GPU for tractography\nRunning pyAFQ using the GPU for tractography is as simple as\n(1) Installing GPUStreamlines using `pip install` and\n(2) passing in the ``jit_backend`` parameter when you create your\n GroupAFQ object.\nTo install GPUStreamlines, do:\n `pip install git+https://github.com/dipy/GPUStreamlines.git`\nThat's step 1 complete! The rest of this example is the same as the GroupAFQ\nexample except with the ``jit_backend`` parameter set.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from AFQ.api.group import GroupAFQ\nimport AFQ.data.fetch as afd\nimport os.path as op\nimport plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start with some example data. The data we will use here is\ngenerated from the\n[Stanford HARDI dataset](https://purl.stanford.edu/ng782rw8378).\nWe then setup our myafq object which we will use to demonstrate\nthe clobber method.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "afd.organize_stanford_data()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set tractography parameters\nWe make create a `tracking_params` variable to define the parameters for tractography.\nThe only parameter we need to set to use the GPU is `jit_backend`,\nwhich we set to \"cuda\". Other backends include: \"metal\", \"webgpu\", or \"numba\".\nNumba is the default. \nNote that the GPU backend will only run for probabilistic tracking,\nwhich is the default.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "tracking_params = dict(n_seeds=1e7,\n random_seeds=True,\n rng_seed=2025,\n jit_backend=\"cuda\",\n trx=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running with the GPU\nThen, run pyAFQ normally.\nThat's it!\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "myafq = GroupAFQ(\n bids_path=op.join(afd.afq_home, 'stanford_hardi'),\n dwi_preproc_pipeline='vistasoft',\n t1_preproc_pipeline='freesurfer',\n tracking_params=tracking_params)\n\nbundle_html = myafq.export(\"all_bundles_figure\")\nplotly.io.show(bundle_html[\"01\"][0])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.13" } }, "nbformat": 4, "nbformat_minor": 0 }