Hê, topic này dành cho python fans chia sẻ kinh nghiệm từ việc install đến các chương trình hay viết bằng Python. Hồi ở VN, học Chem nên không có điều kiện học coding, sang đây thấy C/FORTRAN học không dễ mà trừu tượng quá nên học luôn Python. Thấy dễ dàng hơn hẳn []. Mặc dù bây giờ biết cả FORTRAN và C/C++ một tẹo và bọn này có speed khá khủng nhưng vẫn thích thằng Python và dùng nhiều trong research của mình.
Cái này dành cho anh em chia sẻ những kinh nghiệm tích lũy từ việc google search hay được đào tạo bài bản như các bạn CS. Đây là mấy thứ mà haichit hay dùng.
1. SciPy và Numpy: Hai thứ này thì không thể thiếu nếu như cần tính toán nhiều, hay làm mấy thứ numerical. [Only registered and activated users can see links. ]
2. Phần mềm plot cho Python
Có lẽ phần mềm 2D plot tiện và đẹp nhất vẫn là matplotlib [Only registered and activated users can see links. ]
3. Nếu ai dùng super computer để test Python code thì có thể tham khảo cách set up sau cho python
[Only registered and activated users can see links. ]
Cái này dùng cho Kraken supercomputer
4. Tăng speed python bằng Cython: tạo C-extension cho Python [Only registered and activated users can see links. ]
Cái này dùng ít nhưng test thử thì thấy cũng tăng speed cho Python lên nhiều
Tạm thế đã, đặt cục gạch ở đây để lúc nào có hứng thì viết. Mời các bạn chia sẻ kinh nghiệm. Kiến thức thì vô bờ bến, đặc biệt bây giờ toàn open source, free lesson hay free software thì việc học trở nên đơn giản nhưng chính vì thế mà khó có thể biết mình nên đọc gì. Vì vậy, mục đích của topic là việc chia sẻ những thứ hay ho để rút ngắn thời gian tìm kiếm những thứ mình cần.
___________________________________________________________ Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.
thay đổi nội dung bởi: haichit., 07-16-2009 lúc 12:55 PM.
OpenOpt for Optimization [Only registered and activated users can see links. ]
Some reasons to chose OpenOpt
1. It's free
Take a look at the epigraph. OpenOpt proposes lots of solvers, while many other optimization toolboxes, free as well as commercial ones, propose single solver for each problem type - linear, non-linear, quadratic etc.
Commercial optimization software is very costly
Don't forget: you need to pay plus ~10% yearly to keep your software up-to-date.
Part of money that users spend for commercial closed-code software goes to systems of protection from themselves (i.e. from users) - all those license files linked to network card number, restrictions by CPU number and similar stuff.
There are more and more free solvers appear during recent years, that are so powerful like commercial ones are. First of all I would mention IPOPT, DSDP, PSwarm and ALGENCAN (BTW they are already connected to OpenOpt).
Time and CPUTime elapsed for solver is usually much more less than the one elapsed for objFunc and/or constraints evaluation (+ maybe some matrix operations; being performed by numpy C-code, they are almost as fast as native C/Fortran one). If you want to speed up calculations the most efficient way is rewriting some (slowest) Python funcs (objfunc or some non-linear constraints) to C or Fortran. Connecting C or Fortran code to Python (via f2py, cython, ctypes, SWIG etc) is much more simple than, for example, using MATLAB MEX-funcs.
2. It saves our time
OpenOpt bugfixes require much less time: sometimes several minutes are enough to find, fix and commit changes to svn repository (and/or send the changes via email to user).
BSD license allows connecting OpenOpt to any code, both free and closed-source.
OpenOpt is developed in KUBUNTU Linux using Python 2.5, but AFAIK it works in many other OS (including Windows, MacOS) as well.
Some commercial frameworks provide using of all those dozens of all solver parameters (like pcgtol etc). OpenOpt can't implement all those ones but you can find most appropriate one (using the framework) and then connect you code to solver directly (w/o using OpenOpt).
Using some AD features via OpenOpt oofun for non-linear problems group is capable to speedup some nonlinear solvers in several times (example)
There are lots of problems where objective functions and/or constraints are calculated during hours. Taking into account that sometimes it needs 1000,10000, 100000... number of function evaluations, we should be not surprised that optimization problems often become a project's bottleneck.
Also, here could be mentioned problems that require real-time solution with short time limit, and problems, where optimization subproblems are deeply integrated into long, maybe nested, cycles.
Do you know who is Elisha Gray?
[Only registered and activated users can see links. ]
I'm not surprised if you don't. He was the one who applied for a phone patent 2 hours later than Alexander Graham Bell had done. Are you sure you'll not be just another one Elisha Gray?
Using Python language RAD ability + choosing most efficient solver(s) for your problem(s) can greatly help you to suppress your rival(s).
__________________ Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.
thay đổi nội dung bởi: haichit., 07-18-2009 lúc 11:26 PM
[Only registered and activated users can see links. ]
Trích:
Introduction
F2PY is a tool that provides an easy connection between Python and Fortran languages. F2PY is part of NumPy.
F2PY creates extension modules from (handwritten or F2PY generated) signature files or directly from Fortran sources.
The generated extension modules facilitate:
Calling Fortran 77/90/95, Fortran 90/95 module, and C functions from Python.
Accessing Fortran 77 COMMON blocks and Fortran 90/95 module data (including allocatable arrays) from Python.
Calling Python functions from Fortran or C (call-backs).
Automatically handling the difference in the data storage order of multi-dimensional Fortran and Numerical Python (i.e. C) arrays.
In addition, F2PY can build the generated extension modules to shared libraries with only one command. F2PY uses the numpy.distutils module from NumPy that supports a number of major Fortran compilers. F2PY generated extension modules depend on NumPy that provides a fast multi-dimensional array language facility to Python. For building extension modules with Numeric or Numarray array backend, one can use the older and unmaintained version of F2PY: f2py2e.
Kinh nghiệm bản thân: It's really smart.
Haichit vẫn dùng f2py cho shared library nhưng đang cần import vào static library của python để dùng submit jobs cho computer cluster. Bác nào có cao kiến gì không?
Ở đây hướng dẫn rất tỉ mỉ về việc compile python, numpy và một số code khác statically nhưng lại chả hướng dẫn f2py. Mà kinh nghiệm về mấy thứ này của haichit là số 0 nên ai có kinh nghiệm thì dạy bảo haichit vài đâu. Really Appreciate.
À mà lý do haichit không dùng Fortran vì debug và compile rắc rối quá nên dùng Python cho tiện. [Only registered and activated users can see links. ]
__________________ Không có gì quí hơn độc lập tự do. Tốt nhất là không lấy vợ.
thay đổi nội dung bởi: haichit., 07-22-2009 lúc 09:38 PM