modelx icon indicating copy to clipboard operation
modelx copied to clipboard

Zip archiving the folder

Open fumitoh opened this issue 5 years ago • 7 comments

One more thing as we are talking about model saving. Have you thought about zip archiving the folder? It will save space and make it more convenient to send the model around. We save the model on OneDrive cloud and it ends up syncing a hundered files instead of 1. Using zip archive will be the same as what Excel does with its files. I can also implement this myself.

Originally posted by @alebaran in https://github.com/fumitoh/modelx/issues/32#issuecomment-644176978

fumitoh avatar Jun 15 '20 14:06 fumitoh

Good idea. Looks easy to implement and practical.

fumitoh avatar Jun 15 '20 14:06 fumitoh

import shutil
save_name = 'my_model'
# write model
mx.write_model(model, save_name)
# zip
shutil.make_archive(save_name, 'zip', save_name)
shutil.rmtree(save_name)
# unzip
shutil.unpack_archive(save_name + '.zip', extract_dir='temp')
# read model
model = mx.read_model('temp')
shutil.rmtree('temp')

alebaran avatar Jun 15 '20 15:06 alebaran

Thanks for the code.

fumitoh avatar Jun 15 '20 15:06 fumitoh

https://docs.modelx.io/en/latest/releases/relnotes_v0_8_0.html

fumitoh avatar Jul 06 '20 16:07 fumitoh

Thank you for the quick release, very helpful. One question: do you intentionally zip archive without any compression?

alebaran avatar Jul 15 '20 16:07 alebaran

I wasn’t paying attention to compression. But I did try to write directly to the zip file using zipfile and in-memory files to avoid writing files to the disk.

fumitoh avatar Jul 15 '20 17:07 fumitoh

ZipFile() seems to have compression parameter, which is defaulted to no compression. Here is one of the options making it compress: compression=zipfile.ZIP_DEFLATED

alexeybaran avatar Jul 16 '20 08:07 alexeybaran