Created
June 19, 2020 11:49
-
-
Save yuxuanzhuang/9fb6a7156806a2f65706d118dab3a460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Serialize_IO PR #2723" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/home/scottzhuang/mdanalysis/package/MDAnalysis/topology/guessers.py:80: UserWarning: Failed to guess the mass for the following atom types: DU\n", | |
" warnings.warn(\"Failed to guess the mass for the following atom types: {}\".format(atom_type))\n", | |
"/home/scottzhuang/mdanalysis/package/MDAnalysis/topology/PDBParser.py:327: UserWarning: Invalid elements found in the PDB file, elements attributes will not be populated.\n", | |
" warnings.warn(\"Invalid elements found in the PDB file, \"\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Serialze: 157.210\n", | |
"Pickle: 7.767\n", | |
"Iter: 242.306\n" | |
] | |
} | |
], | |
"source": [ | |
"import io\n", | |
"import os\n", | |
"import shlex\n", | |
"import timeit\n", | |
"from pathlib import Path\n", | |
"from shutil import rmtree\n", | |
"from subprocess import call\n", | |
"from contextlib import contextmanager\n", | |
"import shutil\n", | |
"import MDAnalysis as mda\n", | |
"import pickle \n", | |
"\n", | |
"RAMDISK = Path(\"ramdisk\")\n", | |
"TESTFILE = RAMDISK / \"testfile.pdb\"\n", | |
" \n", | |
"def mount_ramfs():\n", | |
" RAMDISK.mkdir(exist_ok=True)\n", | |
" cmd = shlex.split(f\"sudo mount -t ramfs ramfs {RAMDISK}\")\n", | |
" call(cmd)\n", | |
" \n", | |
" \n", | |
"def umount_ramfs():\n", | |
" cmd = shlex.split(f\"sudo umount {RAMDISK}\")\n", | |
" call(cmd)\n", | |
" RAMDISK.rmdir()\n", | |
" \n", | |
" \n", | |
"def make_test_file():\n", | |
" shutil.copyfile('test_multi.pdb', TESTFILE)\n", | |
"\n", | |
"mount_ramfs()\n", | |
"make_test_file()\n", | |
"\n", | |
"## testcode ##\n", | |
"\n", | |
"def Serialization_IO(testfile):\n", | |
" u = mda.Universe(testfile)\n", | |
"\n", | |
"def Pickle_time(u):\n", | |
" u_p = pickle.loads(pickle.dumps(u))\n", | |
" \n", | |
"def iter_through_traj(u):\n", | |
" for time in range(u.trajectory.n_frames):\n", | |
" u.trajectory[time]\n", | |
" coord = u.atoms.positions\n", | |
" \n", | |
"result_serilize = timeit.timeit(\"Serialization_IO(os.fspath(TESTFILE))\", globals=globals(), number=100)\n", | |
"u_test = mda.Universe(os.fspath(TESTFILE))\n", | |
"result_pickle = timeit.timeit(\"Pickle_time(u_test)\", globals=globals(), number=100)\n", | |
"result_iter = timeit.timeit(\"iter_through_traj(u_test)\", globals=globals(), number=100)\n", | |
"\n", | |
"print(f\"Serialze: {result_serilize:.3f}\")\n", | |
"print(f\"Pickle: {result_pickle:.3f}\")\n", | |
"print(f\"Iter: {result_iter:.3f}\")\n", | |
"\n", | |
"umount_ramfs()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"test.pdb file is 126 MB, 35 frames, 47681 atoms" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"- Create Universe: 1.57 s\n", | |
"- Pickle/Unipickle Universe: 0.078 s\n", | |
"- Iter through Universe: 2.42 s" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Old Serialize Branch PR #2704" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/home/scottzhuang/mdanalysis/package/MDAnalysis/topology/guessers.py:80: UserWarning: Failed to guess the mass for the following atom types: DU\n", | |
" warnings.warn(\"Failed to guess the mass for the following atom types: {}\".format(atom_type))\n", | |
"/home/scottzhuang/mdanalysis/package/MDAnalysis/topology/PDBParser.py:327: UserWarning: Invalid elements found in the PDB file, elements attributes will not be populated.\n", | |
" warnings.warn(\"Invalid elements found in the PDB file, \"\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Serialze: 136.637\n", | |
"Pickle: 8.274\n", | |
"Iter: 254.772\n" | |
] | |
} | |
], | |
"source": [ | |
"import io\n", | |
"import os\n", | |
"import shlex\n", | |
"import timeit\n", | |
"from pathlib import Path\n", | |
"from shutil import rmtree\n", | |
"from subprocess import call\n", | |
"from contextlib import contextmanager\n", | |
"import shutil\n", | |
"import MDAnalysis as mda\n", | |
"import pickle \n", | |
"\n", | |
"RAMDISK = Path(\"ramdisk\")\n", | |
"TESTFILE = RAMDISK / \"testfile.pdb\"\n", | |
" \n", | |
"def mount_ramfs():\n", | |
" RAMDISK.mkdir(exist_ok=True)\n", | |
" cmd = shlex.split(f\"sudo mount -t ramfs ramfs {RAMDISK}\")\n", | |
" call(cmd)\n", | |
" \n", | |
" \n", | |
"def umount_ramfs():\n", | |
" cmd = shlex.split(f\"sudo umount {RAMDISK}\")\n", | |
" call(cmd)\n", | |
" RAMDISK.rmdir()\n", | |
" \n", | |
" \n", | |
"def make_test_file():\n", | |
" shutil.copyfile('test_multi.pdb', TESTFILE)\n", | |
"\n", | |
"mount_ramfs()\n", | |
"make_test_file()\n", | |
"\n", | |
"def Serialization_IO(testfile):\n", | |
" u = mda.Universe(testfile)\n", | |
"\n", | |
"def Pickle_time(u):\n", | |
" u_p = pickle.loads(pickle.dumps(u))\n", | |
" \n", | |
"def iter_through_traj(u):\n", | |
" for time in range(u.trajectory.n_frames):\n", | |
" u.trajectory[time]\n", | |
" coord = u.atoms.positions\n", | |
" \n", | |
"result_serilize = timeit.timeit(\"Serialization_IO(os.fspath(TESTFILE))\", globals=globals(), number=100)\n", | |
"u_test = mda.Universe(os.fspath(TESTFILE))\n", | |
"result_pickle = timeit.timeit(\"Pickle_time(u_test)\", globals=globals(), number=100)\n", | |
"result_iter = timeit.timeit(\"iter_through_traj(u_test)\", globals=globals(), number=100)\n", | |
"\n", | |
"print(f\"Serialze: {result_serilize:.3f}\")\n", | |
"print(f\"Pickle: {result_pickle:.3f}\")\n", | |
"print(f\"Iter: {result_iter:.3f}\")\n", | |
"\n", | |
"umount_ramfs()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"test.pdb file is 126 MB, 35 frames, 47681 atoms" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"\n", | |
"- Create Universe: 1.36 s\n", | |
"- Pickle/Unipickle Universe: 0.082 s\n", | |
"- Iter through Universe: 2.55 s" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "mda_py38", | |
"language": "python", | |
"name": "gsoc" | |
}, | |
"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.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment