This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Using dolphin and shelve: on Ubuntu and on Mac OS X

0 votes

I have run the following script:

from dolfin import *
import shelve

mesh = UnitSquareMesh(3, 3)
V = FunctionSpace(mesh, 'CG', 1)

f = Expression('1 + x[0]*x[1]')
f_proj = project(f, V)

curr_shelf = shelve.open('test_shelf_f')
curr_shelf['dofs of f'] = f_proj.vector().array()
curr_shelf.close()

on Ubuntu, where the shelf gets saved under the filename test_shelf_f (without any extension), and on Mac OS X, where the shelf gets saved under the filename test_shelf_f.db.

Since I developed some code on an Ubuntu machine which now needs to run on a Mac OS X machine, I would like to know how to tell the Mac OS X machine to store the shelf as test_shelf_f.

Any advice will be appreciated.

asked Aug 17, 2015 by kdma-at-dtu FEniCS Novice (590 points)

1 Answer

0 votes

shelve uses anydbm which in turn selects any of four installed DBM-implementations. This is in my opinion a terrible design, as they are not complete compatible with each other. Naming of the files is one of these compatibility-issues.

To fix it, make sure that the same backend is used. (Check import anydbm; print anydbm._name.)

I would recommend changing from shelve, and using something else instead, e.g. h5py.

answered Aug 17, 2015 by Øyvind Evju FEniCS Expert (17,700 points)

Thank you for the feedback.

After running

import anydbm
print anydbm._name

on both machines, I saw that they're both using the backend dumbdbm. Do you happen to know if there are any further settings that I should check and change so that both machines will store the shelf as test_shelf_f?

Thank you also for recommending h5py - I will look into it as soon as I have the chance.

...