Skip to content

Commit

Permalink
Merge pull request JiaweiZhuang#3 from Ouranosinc/fix-75
Browse files Browse the repository at this point in the history
Weights are now returned in memory by default, instead of being written to file. Backward compatibility with the `filename` and `reuse_weights` arguments is preserved.
  • Loading branch information
huard authored Aug 21, 2020
2 parents 603c6fb + b5f3d07 commit 8494718
Show file tree
Hide file tree
Showing 14 changed files with 10,427 additions and 590 deletions.
45 changes: 18 additions & 27 deletions doc/notebooks/Backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import os\n",
Expand Down Expand Up @@ -53,9 +51,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"ds_in = xe.util.grid_2d(-120, 120, 0.4, # longitude range and resolution\n",
Expand Down Expand Up @@ -106,9 +102,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"grid_in = esmf_grid(lon_in.T, lat_in.T)\n",
Expand Down Expand Up @@ -159,9 +153,10 @@
"text/plain": [
" C_CONTIGUOUS : True\n",
" F_CONTIGUOUS : False\n",
" OWNDATA : False\n",
" OWNDATA : True\n",
" WRITEABLE : True\n",
" ALIGNED : True\n",
" WRITEBACKIFCOPY : False\n",
" UPDATEIFCOPY : False"
]
},
Expand All @@ -187,6 +182,7 @@
" OWNDATA : False\n",
" WRITEABLE : True\n",
" ALIGNED : True\n",
" WRITEBACKIFCOPY : False\n",
" UPDATEIFCOPY : False"
]
},
Expand All @@ -209,14 +205,12 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"filename = 'test_weights.nc' # weight filename\n",
"if os.path.exists(filename):\n",
" os.remove(filename) # ESMPy will crash if the file exists"
" os.remove(filename) # ESMPy will complain if the file exists"
]
},
{
Expand All @@ -235,8 +229,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 7.06 s, sys: 382 ms, total: 7.44 s\n",
"Wall time: 7.57 s\n"
"CPU times: user 4.24 s, sys: 220 ms, total: 4.46 s\n",
"Wall time: 4.47 s\n"
]
}
],
Expand Down Expand Up @@ -329,8 +323,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 2.35 s, sys: 662 ms, total: 3.01 s\n",
"Wall time: 3.09 s\n"
"CPU times: user 1.33 s, sys: 548 ms, total: 1.88 s\n",
"Wall time: 1.88 s\n"
]
}
],
Expand Down Expand Up @@ -359,6 +353,7 @@
" OWNDATA : False\n",
" WRITEABLE : True\n",
" ALIGNED : True\n",
" WRITEBACKIFCOPY : False\n",
" UPDATEIFCOPY : False"
]
},
Expand Down Expand Up @@ -463,8 +458,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 443 ms, sys: 165 ms, total: 609 ms\n",
"Wall time: 620 ms\n"
"CPU times: user 529 ms, sys: 195 ms, total: 725 ms\n",
"Wall time: 722 ms\n"
]
}
],
Expand Down Expand Up @@ -505,9 +500,7 @@
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"np.testing.assert_equal(data_out_scipy, data_out_esmpy) # exactly the same"
Expand All @@ -516,9 +509,7 @@
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"os.remove(filename) # clean-up"
Expand All @@ -541,7 +532,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
"version": "3.8.2"
},
"toc": {
"nav_menu": {},
Expand Down
Loading

0 comments on commit 8494718

Please sign in to comment.