├── .gitignore
├── LICENSE
├── README.md
├── data
└── water
│ └── data_0
│ ├── set.000
│ ├── box.npy
│ ├── coord.npy
│ ├── energy.npy
│ └── force.npy
│ ├── type.raw
│ └── type_map.raw
├── deepmd
└── tutorial
│ └── model_descriptor_inference.ipynb
├── model
└── se_e2_a
│ └── water-14000.pb
└── tutorial
├── machine_learning
├── 1.1_introduction.ipynb
└── mtters_needing_attention.ipynb
└── others
├── figs
├── optimization-1.png
├── optimization-2.png
├── optimization-3.png
├── optimization-4.png
└── optimization-5.png
└── optimization.ipynb
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # deepmd-kit-tutorial
--------------------------------------------------------------------------------
/data/water/data_0/set.000/box.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/data/water/data_0/set.000/box.npy
--------------------------------------------------------------------------------
/data/water/data_0/set.000/coord.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/data/water/data_0/set.000/coord.npy
--------------------------------------------------------------------------------
/data/water/data_0/set.000/energy.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/data/water/data_0/set.000/energy.npy
--------------------------------------------------------------------------------
/data/water/data_0/set.000/force.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/data/water/data_0/set.000/force.npy
--------------------------------------------------------------------------------
/data/water/data_0/type.raw:
--------------------------------------------------------------------------------
1 | 0
2 | 0
3 | 0
4 | 0
5 | 0
6 | 0
7 | 0
8 | 0
9 | 0
10 | 0
11 | 0
12 | 0
13 | 0
14 | 0
15 | 0
16 | 0
17 | 0
18 | 0
19 | 0
20 | 0
21 | 0
22 | 0
23 | 0
24 | 0
25 | 0
26 | 0
27 | 0
28 | 0
29 | 0
30 | 0
31 | 0
32 | 0
33 | 0
34 | 0
35 | 0
36 | 0
37 | 0
38 | 0
39 | 0
40 | 0
41 | 0
42 | 0
43 | 0
44 | 0
45 | 0
46 | 0
47 | 0
48 | 0
49 | 0
50 | 0
51 | 0
52 | 0
53 | 0
54 | 0
55 | 0
56 | 0
57 | 0
58 | 0
59 | 0
60 | 0
61 | 0
62 | 0
63 | 0
64 | 0
65 | 1
66 | 1
67 | 1
68 | 1
69 | 1
70 | 1
71 | 1
72 | 1
73 | 1
74 | 1
75 | 1
76 | 1
77 | 1
78 | 1
79 | 1
80 | 1
81 | 1
82 | 1
83 | 1
84 | 1
85 | 1
86 | 1
87 | 1
88 | 1
89 | 1
90 | 1
91 | 1
92 | 1
93 | 1
94 | 1
95 | 1
96 | 1
97 | 1
98 | 1
99 | 1
100 | 1
101 | 1
102 | 1
103 | 1
104 | 1
105 | 1
106 | 1
107 | 1
108 | 1
109 | 1
110 | 1
111 | 1
112 | 1
113 | 1
114 | 1
115 | 1
116 | 1
117 | 1
118 | 1
119 | 1
120 | 1
121 | 1
122 | 1
123 | 1
124 | 1
125 | 1
126 | 1
127 | 1
128 | 1
129 | 1
130 | 1
131 | 1
132 | 1
133 | 1
134 | 1
135 | 1
136 | 1
137 | 1
138 | 1
139 | 1
140 | 1
141 | 1
142 | 1
143 | 1
144 | 1
145 | 1
146 | 1
147 | 1
148 | 1
149 | 1
150 | 1
151 | 1
152 | 1
153 | 1
154 | 1
155 | 1
156 | 1
157 | 1
158 | 1
159 | 1
160 | 1
161 | 1
162 | 1
163 | 1
164 | 1
165 | 1
166 | 1
167 | 1
168 | 1
169 | 1
170 | 1
171 | 1
172 | 1
173 | 1
174 | 1
175 | 1
176 | 1
177 | 1
178 | 1
179 | 1
180 | 1
181 | 1
182 | 1
183 | 1
184 | 1
185 | 1
186 | 1
187 | 1
188 | 1
189 | 1
190 | 1
191 | 1
192 | 1
193 |
--------------------------------------------------------------------------------
/data/water/data_0/type_map.raw:
--------------------------------------------------------------------------------
1 | O
2 | H
3 |
--------------------------------------------------------------------------------
/deepmd/tutorial/model_descriptor_inference.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "本篇教程将介绍如何使用deepmd和训练好的模型,得到数据集上descriptor或模型的输出结果,descriptor的输出结果可以作为特征在下游任务中使用。 \n",
8 | "运行本教程需要安装`deepmd-kit`和`dpdata` \n",
9 | "- `deepmd-kit`安装介绍:https://github.com/deepmodeling/deepmd-kit \n",
10 | "- `dpdata`支持从vasp, lammps, deepmd, Amber, cp2k等软件读取输入数据,安装介绍可参考:https://github.com/deepmodeling/dpdata \n",
11 | "\n",
12 | "本篇教程的内容可以参考代码注释:https://github.com/deepmodeling/deepmd-kit/blob/v2.1.5/deepmd/infer/deep_pot.py"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "import dpdata\n",
22 | "from deepmd.infer import DeepPot\n",
23 | "\n",
24 | "import numpy as np"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "# 训练好的模型路径\n",
34 | "model_path = '../../model/se_e2_a/water-14000.pb'\n",
35 | "# 数据集的路径,数据集可以是deepmd的标准格式或者VASP\n",
36 | "system_path = '../../data/water/data_0'\n",
37 | "max_nframe_each = 10\n",
38 | "type_map = [\"O\", \"H\"]"
39 | ]
40 | },
41 | {
42 | "cell_type": "markdown",
43 | "metadata": {},
44 | "source": [
45 | "## 获取descriptor的输出"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "# 加载模型\n",
55 | "dp = DeepPot(model_path)\n",
56 | "\n",
57 | "# 使用dpdata读取数据\n",
58 | "ms = dpdata.System(type_map=type_map)\n",
59 | "ms.from_deepmd_npy(system_path, labeled=False)\n",
60 | "\n",
61 | "# 获取当前system的frame数量\n",
62 | "nframe = ms.get_nframes()\n",
63 | " \n",
64 | "# nframes x natoms x 3\n",
65 | "coord = ms['coords']\n",
66 | "# nframes x 9\n",
67 | "cell = ms['cells'].reshape([nframe, -1])\n",
68 | "# List[int]\n",
69 | "# len(atype) == natoms, 且第i个原子的元素种类为type_map[atype[i]]\n",
70 | "atype = ms['atom_types'].tolist()\n",
71 | "\n",
72 | "start_idx = 0\n",
73 | "end_idx = start_idx + max_nframe_each\n",
74 | "\n",
75 | "descriptor_out = []\n",
76 | "# 限制每次inference时的frame数量,防止内存溢出(Out Of Memory, 简称OOM)\n",
77 | "while start_idx < nframe:\n",
78 | " out = \\\n",
79 | " dp.eval_descriptor(coord[start_idx: end_idx, ...], \n",
80 | " cell[start_idx: end_idx, :],\n",
81 | " atype)\n",
82 | " descriptor_out.append(out)\n",
83 | " start_idx += max_nframe_each\n",
84 | " end_idx += max_nframe_each\n",
85 | "\n",
86 | "# nframes x natoms x feature_num\n",
87 | "descriptor_out = np.concatenate(descriptor_out, axis=0)\n",
88 | "descriptor_out.shape"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "metadata": {},
94 | "source": [
95 | "descriptor的输出结果为nframes x natoms x feature_num, 其中feature_num的大小跟input.json中的参数有关,在这个例子中为1600"
96 | ]
97 | },
98 | {
99 | "cell_type": "markdown",
100 | "metadata": {},
101 | "source": [
102 | "## 获取模型的输出"
103 | ]
104 | },
105 | {
106 | "cell_type": "code",
107 | "execution_count": null,
108 | "metadata": {},
109 | "outputs": [],
110 | "source": [
111 | "# 加载模型\n",
112 | "dp = DeepPot(model_path)\n",
113 | "\n",
114 | "# 使用dpdata读取数据\n",
115 | "ms = dpdata.System(type_map=type_map)\n",
116 | "ms.from_deepmd_npy(system_path, labeled=False)\n",
117 | "\n",
118 | "nframe = ms.get_nframes()\n",
119 | "# nframes x natoms x 3\n",
120 | "coord = ms['coords']\n",
121 | "# nframes x 9\n",
122 | "cell = ms['cells'].reshape([nframe, -1])\n",
123 | "# List[int]\n",
124 | "# len(atype) == natoms, 且第i个原子的元素种类为type_map[atype[i]]\n",
125 | "atype = ms['atom_types'].tolist()\n",
126 | "\n",
127 | "start_idx = 0\n",
128 | "end_idx = start_idx + max_nframe_each\n",
129 | "\n",
130 | "energy = []\n",
131 | "force = []\n",
132 | "virial = []\n",
133 | "while start_idx < nframe:\n",
134 | " e, f, v = \\\n",
135 | " dp.eval(coord[start_idx: end_idx, :], \n",
136 | " cell[start_idx: end_idx, :],\n",
137 | " atype)\n",
138 | " \n",
139 | " energy.append(e)\n",
140 | " force.append(f)\n",
141 | " virial.append(v)\n",
142 | "\n",
143 | " start_idx += max_nframe_each\n",
144 | " end_idx += max_nframe_each\n",
145 | "\n",
146 | "# [nframe]\n",
147 | "energy = np.concatenate(energy, axis=0).squeeze()\n",
148 | "# nframe x -1\n",
149 | "force = np.concatenate(force, axis=0).reshape([nframe, -1])\n",
150 | "# nframe x 9\n",
151 | "virial = np.concatenate(virial, axis=0).reshape([nframe, -1])"
152 | ]
153 | },
154 | {
155 | "cell_type": "markdown",
156 | "metadata": {},
157 | "source": [
158 | "模型将输出energy(shape 为[ nframe ]), force(shape为[nframe, -1]), virial force(shape为[nframe, -9]). 其中shape为-1的意思是该维度的值可能为任意值,将在计算其它维度的大小之后再确定。例如shape[a, b, c]的矩阵reshape([nframe, -1])之后shape将变成[nframe, a * b * c / nframe]. \n",
159 | "输出的结果可以保存标准的npy格式,并重新被dpdata读取:"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "from pathlib import Path\n",
169 | "save_path = Path('./system')\n",
170 | "# 将不含energy, force, virial force的data保存成标准deepmd格式\n",
171 | "ms.to('deepmd/npy', save_path)\n",
172 | "# 找到coord.npy的路径\n",
173 | "coord_path = list(save_path.glob('**/coord.npy'))[0]\n",
174 | "\n",
175 | "# 将energy, force, virial force跟coord.npy保存在同一路径下,组成标准的deepmd格式\n",
176 | "with open(coord_path.parent / 'energy.npy', 'wb') as f:\n",
177 | " np.save(f, energy)\n",
178 | "with open(coord_path.parent / 'force.npy', 'wb') as f:\n",
179 | " np.save(f, force)\n",
180 | "with open(coord_path.parent / 'virial.npy', 'wb') as f:\n",
181 | " np.save(f, virial)"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": null,
187 | "metadata": {},
188 | "outputs": [],
189 | "source": [
190 | "# 读取包含energy, force, virial force的数据\n",
191 | "ls = dpdata.LabeledSystem()\n",
192 | "ls.from_deepmd_npy('./system/')"
193 | ]
194 | }
195 | ],
196 | "metadata": {
197 | "kernelspec": {
198 | "display_name": "Python 3.8.13 ('dp2.1.5')",
199 | "language": "python",
200 | "name": "python3"
201 | },
202 | "language_info": {
203 | "codemirror_mode": {
204 | "name": "ipython",
205 | "version": 3
206 | },
207 | "file_extension": ".py",
208 | "mimetype": "text/x-python",
209 | "name": "python",
210 | "nbconvert_exporter": "python",
211 | "pygments_lexer": "ipython3",
212 | "version": "3.8.13"
213 | },
214 | "orig_nbformat": 4,
215 | "vscode": {
216 | "interpreter": {
217 | "hash": "8ba00acb958a154a84efb1320fed20ca107ed539226fcb2e3aa961180e579300"
218 | }
219 | }
220 | },
221 | "nbformat": 4,
222 | "nbformat_minor": 2
223 | }
224 |
--------------------------------------------------------------------------------
/model/se_e2_a/water-14000.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/model/se_e2_a/water-14000.pb
--------------------------------------------------------------------------------
/tutorial/machine_learning/1.1_introduction.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "本教程面向非计算机专业的同学,将介绍一些使用deepmd-kit(分子动力学计算)、deepks(量化计算)等软件时可能用到的深度学习知识。在这个教程中你将学到如何训练神经网络来拟合一个简单的函数。神经网络模型的训练无需使用显卡,在个人笔记本电脑上花费几十秒就能完成训练(支持windows/linux/mac os系统)。\n",
8 | "\n",
9 | "运行教程中的代码需要安装pytorch(cpu版本),matplotlib(用于画图)和jupyter notebook,建议安装Anaconda来运行本教程,安装方法网上可以搜到。安装好相关环境之后,可以使用下面的命令安装pytorch、matplotlib和jupyter notebook\n",
10 | "\n",
11 | "```\n",
12 | "# conda安装\n",
13 | "conda install pytorch -c pytorch\n",
14 | "conda install matplotlib jupyter notebook\n",
15 | "\n",
16 | "# 或者pip安装(与conda安装只能二选一)\n",
17 | "pip install pytorch\n",
18 | "pip install matplotlib jupyter notebook\n",
19 | "```"
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {},
25 | "source": [
26 | "理论上神经网络可以拟合任意函数,这里将给出一个神经网络拟合`cos`函数的例子,首先用python写一个`cos`函数:"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": 78,
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "import math\n",
36 | "def func(x):\n",
37 | " return math.cos(x)"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {},
43 | "source": [
44 | "上面的`func`函数接受一个输入x,输出cos(x)。接下利用`func`函数生成一批数据"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 79,
50 | "metadata": {},
51 | "outputs": [],
52 | "source": [
53 | "# 先定义x的区间为0-4和6-8,然后在这两个区间上随机生成500个数据\n",
54 | "intervals = [[0, 4], [6, 8]]\n",
55 | "data_num = 500"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 80,
61 | "metadata": {},
62 | "outputs": [
63 | {
64 | "name": "stdout",
65 | "output_type": "stream",
66 | "text": [
67 | "data_num: 499\n"
68 | ]
69 | }
70 | ],
71 | "source": [
72 | "import random\n",
73 | "from copy import deepcopy\n",
74 | "\n",
75 | "# 给定x的区间和数据量,根据func生成相应的数据\n",
76 | "def random_data(intervals, data_num):\n",
77 | " total_len = 0\n",
78 | " for interval in intervals:\n",
79 | " total_len += (interval[1] - interval[0])\n",
80 | " data_density = data_num / total_len\n",
81 | "\n",
82 | " data_pairs = []\n",
83 | " for interval in intervals:\n",
84 | " # 求出该区间上需要产生的数据有多少个\n",
85 | " _data_num = int((interval[1] - interval[0]) * data_density)\n",
86 | " for i in range(_data_num):\n",
87 | " x = random.uniform(interval[0], interval[1])\n",
88 | " y = func(x)\n",
89 | " data_pairs.append((x, y))\n",
90 | " print('data_num:', len(data_pairs))\n",
91 | " return data_pairs\n",
92 | "\n",
93 | "def data_pairs_to_list(data_pairs, shuffle=False):\n",
94 | " x_list = []\n",
95 | " y_list = []\n",
96 | " if shuffle:\n",
97 | " data_pairs = deepcopy(data_pairs)\n",
98 | " random.shuffle(data_pairs)\n",
99 | "\n",
100 | " for d in data_pairs:\n",
101 | " x_list.append([d[0]])\n",
102 | " y_list.append([d[1]])\n",
103 | " return x_list, y_list \n",
104 | "\n",
105 | "data_pairs = random_data(intervals, data_num)"
106 | ]
107 | },
108 | {
109 | "cell_type": "markdown",
110 | "metadata": {},
111 | "source": [
112 | "因为有取整操作,只产生了499个数据,但这对后面的操作没有有影响。 \n",
113 | "接下来将会用到一个三层的神经网络模型,每层网络都由一个线性层(nn.Linear, 即$y=a*x+b$)和一个激活函数(nn.ReLU, 即activation(x) = max(x, 0))组成,计算方式为: \n",
114 | "$$y = max(a * x + b, 0)$$\n",
115 | "其中x为当前层的输入,a和b可以理解为神经元,在模型训练的过程中它们的值会根据输入的数据发生改变,完成对数据的学习。激活函数activation(x)的计算方式为max(x, 0),即当x大于0时,保持不变,当x小于0时输出0。很多个这样的函数堆叠之后就形成了神经网络: \n",
116 | "$y1 = max(a1 * x1 + b1, 0)$ \n",
117 | "$y2 = max(a2 * y1 + b2, 0)$ \n",
118 | "$y3 = max(a3 * y2 + b3, 0)$ \n",
119 | "... \n",
120 | "使用Deepmd和Deepks等软件时,神经网络都已经写好,只需要调节相关参数,准备数据并训练就行。下面给出的这个神经网络有三个参数可以调节:\n",
121 | "- `width`: 代表每一层网络神经单元的数量,`width`值必须大于等于2;\n",
122 | "- `depth`: 代表有几层神经网络,`depth`值必须大于等于2,且最好小于10;\n",
123 | "- `activation`:激活函数种类,只能选择`relu`或`tanh`;\n",
124 | "\n",
125 | "Deepmd-kit中用到的神经网络,以及该网络可以调节的参数跟下面这个神经网络模型几乎完全一样:"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": 81,
131 | "metadata": {},
132 | "outputs": [],
133 | "source": [
134 | "import torch\n",
135 | "import torch.nn as nn\n",
136 | "\n",
137 | "class FittingNet(nn.Module):\n",
138 | " def __init__(self, width: int, depth: int, activation: str) -> None:\n",
139 | " super().__init__()\n",
140 | " assert width >= 2, 'width should be greater than 2'\n",
141 | " assert activation in {\"relu\", \"tanh\"}, \"activation should be relu or tanh\"\n",
142 | " \n",
143 | " self.width = width\n",
144 | " self.depth = depth\n",
145 | " self.activation = nn.ReLU() if activation == 'relu' else nn.Tanh()\n",
146 | " self.layer1 = nn.Linear(1, width)\n",
147 | " layers = []\n",
148 | " for i in range(depth - 2):\n",
149 | " layers.append(nn.Linear(width, width))\n",
150 | " layers.append(self.activation)\n",
151 | " self.layers = nn.Sequential(*layers)\n",
152 | " self.layer3 = nn.Linear(width, 1)\n",
153 | " \n",
154 | " def forward(self, inputs):\n",
155 | " inputs1 = self.activation(self.layer1(inputs))\n",
156 | " if self.depth > 2:\n",
157 | " inputsn = self.layers(inputs1)\n",
158 | " ret = self.layer3(inputsn)\n",
159 | " return ret"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "接下还要实现一套训练代码。"
167 | ]
168 | },
169 | {
170 | "cell_type": "code",
171 | "execution_count": 88,
172 | "metadata": {},
173 | "outputs": [
174 | {
175 | "name": "stdout",
176 | "output_type": "stream",
177 | "text": [
178 | "steps: 200, loss: 0.0849, lr: 0.0080\n",
179 | "steps: 400, loss: 0.0505, lr: 0.0064\n",
180 | "steps: 600, loss: 0.0342, lr: 0.0051\n",
181 | "steps: 800, loss: 0.0258, lr: 0.0041\n",
182 | "steps: 1000, loss: 0.0207, lr: 0.0033\n",
183 | "steps: 1200, loss: 0.0173, lr: 0.0026\n",
184 | "steps: 1400, loss: 0.0149, lr: 0.0021\n",
185 | "steps: 1600, loss: 0.0131, lr: 0.0017\n",
186 | "steps: 1800, loss: 0.0117, lr: 0.0013\n"
187 | ]
188 | }
189 | ],
190 | "source": [
191 | "batch_size = 10\n",
192 | "x_list, y_list = data_pairs_to_list(data_pairs)\n",
193 | "x_list = torch.tensor(x_list)\n",
194 | "y_list = torch.tensor(y_list)\n",
195 | "\n",
196 | "model = FittingNet(width=10, depth=3, activation='relu')\n",
197 | "opt = torch.optim.SGD(model.parameters(), lr=0.01)\n",
198 | "scheduler = torch.optim.lr_scheduler.StepLR(opt, 200, 0.8)\n",
199 | "model.train()\n",
200 | "\n",
201 | "loss_list = []\n",
202 | "start_idx = 0\n",
203 | "end_idx = batch_size\n",
204 | "numb_steps = 2000\n",
205 | "for numb_steps in range(numb_steps):\n",
206 | " while end_idx < len(x_list):\n",
207 | " xs = x_list[start_idx: end_idx, :]\n",
208 | " ys_label = y_list[start_idx: end_idx, :]\n",
209 | " \n",
210 | " ys = model(xs)\n",
211 | " \n",
212 | " loss = ((ys - ys_label)**2).sum() / batch_size\n",
213 | " loss_list.append(loss.item())\n",
214 | " \n",
215 | " opt.zero_grad()\n",
216 | " loss.backward()\n",
217 | " opt.step()\n",
218 | " \n",
219 | " start_idx += batch_size\n",
220 | " end_idx += batch_size\n",
221 | " \n",
222 | " start_idx = 0\n",
223 | " end_idx = batch_size\n",
224 | " scheduler.step()\n",
225 | " if numb_steps > 0 and numb_steps % 200 == 0:\n",
226 | " print('steps: {}, loss: {:.4f}, lr: {:.4f}'.format(numb_steps, sum(loss_list) / len(loss_list), opt.param_groups[0][\"lr\"]))\n",
227 | " "
228 | ]
229 | },
230 | {
231 | "cell_type": "markdown",
232 | "metadata": {},
233 | "source": [
234 | "训练过程简单来说就是有n个标注好的训练数据,即n个`x`值和n个`y_label`值,每个`x`, `y_label`都有`y_label = func(x)`. 将n个`x`输入模型,得到模型输出的n个`y_model_output`,然后求`y_label`和`y_model_output`的平方差,就能得到误差loss,即$loss = (y\\_label - y\\_model\\_output)^2$。利用求导公式可以将误差传递回模型中让模型学习,从而让模型的输出越来越接近`y_label`。\n",
235 | "\n",
236 | "训练大概十几秒就能完成。训练过程中应该观察到`loss`值快速下降。 接下来对训练的结果进行可视化,首先来看看训练数据的样子"
237 | ]
238 | },
239 | {
240 | "cell_type": "code",
241 | "execution_count": 89,
242 | "metadata": {},
243 | "outputs": [
244 | {
245 | "data": {
246 | "text/plain": [
247 | ""
248 | ]
249 | },
250 | "execution_count": 89,
251 | "metadata": {},
252 | "output_type": "execute_result"
253 | },
254 | {
255 | "data": {
256 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAAOXRFWHRTb2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xmRm883sMjMbg9zv1j+ZmW93a5UgOcLp8IfT9HILgNBHqJnZ/wPwPsmrnUM3Awh9MEKeGYhIs5DjIIDrSQ53/j5vRq7vzhdD/XqjKDOzMyQfAbAeQB2A58xsV8hhAQBIrgRwI4CLSB4C8JSZ/TDcqDAZwJcA7HDa4gHgcTNbF15IZ10C4HlnRMcQAC+aWaSGa0bMxQBezX13YCiAfzCz18MN6ay/BtDq3Jy9B+C/hhwPAIDkcORGGP63sGPpZ2abSb4M4F0AZwBshY9LTSRi+KiIiBSXlKYhEREpQolARCThlAhERBJOiUBEJOGUCEREEk6JQEQk4ZQIREQS7v8DLZjZa13UkIgAAAAASUVORK5CYII=",
257 | "text/plain": [
258 | ""
259 | ]
260 | },
261 | "metadata": {
262 | "needs_background": "light"
263 | },
264 | "output_type": "display_data"
265 | }
266 | ],
267 | "source": [
268 | "import matplotlib.pyplot as plt\n",
269 | "\n",
270 | "plt.scatter(x_list, y_list)"
271 | ]
272 | },
273 | {
274 | "cell_type": "markdown",
275 | "metadata": {},
276 | "source": [
277 | "上图就是训练数据,可以看到我们实现的`func`,也就是`cos`在指定区间[0,4]和[6,8]上的样子。 \n",
278 | "接下来再次在[0, 8]范围内随机生成100个x值作为神经网络的输入,看看神经网络的输出跟函数`func`的输出有什么区别。"
279 | ]
280 | },
281 | {
282 | "cell_type": "code",
283 | "execution_count": 90,
284 | "metadata": {},
285 | "outputs": [
286 | {
287 | "name": "stdout",
288 | "output_type": "stream",
289 | "text": [
290 | "data_num: 100\n"
291 | ]
292 | }
293 | ],
294 | "source": [
295 | "intervals = [[0, 8]]\n",
296 | "data_pairs_new = random_data(intervals, 100)\n",
297 | "x_list_new, y_list_new = data_pairs_to_list(data_pairs_new)\n",
298 | "x_list_new = torch.tensor(x_list_new)\n",
299 | "\n",
300 | "model.eval()\n",
301 | "with torch.no_grad():\n",
302 | " y_model_output = model(x_list_new)\n"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": 91,
308 | "metadata": {},
309 | "outputs": [
310 | {
311 | "data": {
312 | "text/plain": [
313 | ""
314 | ]
315 | },
316 | "execution_count": 91,
317 | "metadata": {},
318 | "output_type": "execute_result"
319 | },
320 | {
321 | "data": {
322 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAvJklEQVR4nO3df3icZZno8e89Cb+KJekPfgnNhN11DaxCSgopugKLri2rFyi77qqBdVuxCxQyM3XPOR7qodNziNeec7Qzk7bgKVBXaNT1KB65VmkVV0Svi1SSNpQfjS5Ck1bAttCEYos0ee/zx/POZCa/mjSTvPPj/lxXruZ932nmaTpzz/Pez/Pcj6gqxhhjSl8o6AYYY4yZGRbwjTGmTFjAN8aYMmEB3xhjyoQFfGOMKROVQTdgPPPnz9fa2tqgm2GMMUWjs7PzoKqeOdq1gg74tbW1dHR0BN0MY4wpGiLSM9Y1S+kYY0yZsIBvjDFlwgK+McaUCQv4xhhTJizgG2MKy/D6XlbvK28s4BtjCkc8DtHoUJBXdcfxeHBtKiEW8I0xhUEVHn0UWltdkPc8iETc8dat7thMiRRyeeRFixapzcM3pkxcdRU8/zwcPDjyWnOz+3POHOvtH4eIdKrqotGuWQ/fGBM8z4M33nDBfv783Gvz57vrra1w6JDl9KfAAr4xJnihEHR2wiWXjOzhHzwIGzYM9fLXrp359pWI0gv4NsJvTHESgSuvHPu6quvl9/XB4OCMNauUlFbAj8chFssd4Y/FLOdnTDHwPHjggbGvr1/vevlf+QosWgRXXz1jTSsVeQn4IrJZRPaLyLNjXBcRaRWRF0Rkl4hcmo/nzaHqPvlTKTZXxQiJsrkqBqmUO289fWMKl+e5IH7kCPuZT5LbR31Y9/P+47q6oL/fevqTlK8e/r8AS8e5fi3wLv9rBXBvnp53iAhtixJsrIy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JGXcAbX6n7EVgWcDtyRCRWbhZfv8YdFuyqep2EfkOsAMYAHYyhTILJTEt0xhjzPGVSkrHGGPMcVjAN8aYMmEB3xhjyoQFfGOMKRMW8I0xpkxYwDfGmDJhAd8YY8rE/wcBZAd4m3f9uQAAAABJRU5ErkJggg==",
323 | "text/plain": [
324 | ""
325 | ]
326 | },
327 | "metadata": {
328 | "needs_background": "light"
329 | },
330 | "output_type": "display_data"
331 | }
332 | ],
333 | "source": [
334 | "plt.scatter(x_list_new, y_list_new, c='b')\n",
335 | "plt.scatter(x_list_new, y_model_output, c='r', marker='x')"
336 | ]
337 | },
338 | {
339 | "cell_type": "markdown",
340 | "metadata": {},
341 | "source": [
342 | "上图中蓝色的圆点是我们定义的函数`func`也就是`cos`的值,而红色的x点为模型的输出。可以看到在[0, 4]和[6, 8]区间上,模型的输出结果和`func`的输出非常吻合,而在[4, 6]区间上,尽管红色和蓝色的值非常接近,但偏差明显比[0, 4]和[6, 8]区间大。\n",
343 | "\n",
344 | "可以尝试将`func`中的函数替换成其它任意函数来测试这个模型,比如可以替换成分段函数:"
345 | ]
346 | },
347 | {
348 | "cell_type": "code",
349 | "execution_count": 66,
350 | "metadata": {},
351 | "outputs": [],
352 | "source": [
353 | "def func(x):\n",
354 | " if x <= 0:\n",
355 | " return -1\n",
356 | " elif 0 < x <= 1:\n",
357 | " return 1\n",
358 | " elif 1 < x <= 2:\n",
359 | " return 3\n",
360 | " elif 2 < x <= 3:\n",
361 | " return 1\n",
362 | " else:\n",
363 | " return 0"
364 | ]
365 | },
366 | {
367 | "cell_type": "markdown",
368 | "metadata": {},
369 | "source": [
370 | "替换成上面的分段函数后,选择在区间[0, 2.5]上生成500个训练数据,在区间[0, 4]上画图比较结果,就能得到下面这张图: \n",
371 | "\n",
372 | "\n",
373 | "在这张图上可以看到,当输入x的范围在[0, 2.5]时,模型跟`func`的结果吻合地很好,但在x超过2.5之后开始出现明显的偏差,而当x>3时,模型的预测结果完全错误。这是因为训练数据是在0 < x < 2.5的范围上生成的,模型从未见过x > 3的数据,而恰好x > 3时`func`的输出发生了巨大的变化,因而模型无法预测。换而言之,**模型无法预测没有学过的东西!** "
374 | ]
375 | },
376 | {
377 | "cell_type": "markdown",
378 | "metadata": {},
379 | "source": [
380 | "教程看到这里,建议尝试将`func`中的函数替换成其它函数,并改变训练的参数,如生成的数据量,模型的`width`和`depth`,训练的步数等来观察训练的情况,目标是使得loss尽可能地低。在训练时有这么几个问题需要注意:\n",
381 | "1. `batch_size`代表每次迭代用多少个数据来训练,一般来说这个值越大,训练出来的模型效果越好。但在实践中`batch_size`越大,消耗的内存/显存越多,甚至会导致内存溢出错误(OOM,out of memory)。\n",
382 | "2. 一般来说`func`越复杂,需要的神经网络越大(`width`和`depth`都需要加大),需要的数据也越多。自己训练时,`width`设置为2~40,`depth`设置为2~4已经足够用了。\n",
383 | "3. 如果loss降不下去,一般首先考虑的是增加训练步数和数据量,调节loss策略,再考虑加大模型;\n",
384 | "4. 实践中会将数据集分成训练集+测试集(上面的代码中没有实现),当训练集和测试集上的loss都不再下降时,认为模型训练已经完成;在这个教程中可以认为当训练集的loss不再降低时,训练完成;"
385 | ]
386 | },
387 | {
388 | "cell_type": "markdown",
389 | "metadata": {},
390 | "source": [
391 | "理论上神经网络可以逼近任意函数,例如图片分类(输入一张图片,输出图片类别),物体检测(输入一张图片,输出图片物体的类别和位置),自然语言处理(输入一句话,输出针对这句话的回答)等等。只需要将这些输入转换为矩阵,输入模型得到结果,再转换为人类可以理解的输出即可。\n",
392 | "\n",
393 | "在量子化学计算和分子动力学模拟中,很自然就可以想到用神经网络来逼近复杂的势能面,代替第一性原理计算。Deepmd-kit的输入为原子的坐标和元素种类,输出为体系的energy,每个原子的受力force和体系的virial force。其计算速度是第一性原理计算的1000倍以上,更重要的是Deepmd-kit的计算时间跟体系原子数成正比,而传统的第一性原理计算如DFT,其消耗的时间与体系原子数的三次方成正比,因此使用Deepmd-kit可以完成上亿原子的动力学模拟,而这么大的体系使用DFT甚至连算单点能都做不到。 \n",
394 | "此外,在上面的实验中可以观察到一个现象:模型在数据集的覆盖范围[0, 4]和[6, 8]区间上表现很好,而在没有覆盖到的区间如[4, 6]上表现就会下降。因此在训练模型时,一个重要的问题是如何产生一个分布足够均匀的数据集,使得模型在待研究的区间上都能保持良好的精度。Deepmd-kit有一个配套的生产数据的工具叫dpgen,可以自动地寻找模型没有覆盖到的区间来生成标注数据。之后的教程中将会介绍这些工具的原理和使用方法: \n",
395 | "deepmd-kit项目: https://github.com/deepmodeling/deepmd-kit \n",
396 | "dpgen项目: https://github.com/deepmodeling/dpgen"
397 | ]
398 | }
399 | ],
400 | "metadata": {
401 | "kernelspec": {
402 | "display_name": "Python 3.8.10 64-bit",
403 | "language": "python",
404 | "name": "python3"
405 | },
406 | "language_info": {
407 | "codemirror_mode": {
408 | "name": "ipython",
409 | "version": 3
410 | },
411 | "file_extension": ".py",
412 | "mimetype": "text/x-python",
413 | "name": "python",
414 | "nbconvert_exporter": "python",
415 | "pygments_lexer": "ipython3",
416 | "version": "3.8.10"
417 | },
418 | "orig_nbformat": 4,
419 | "vscode": {
420 | "interpreter": {
421 | "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
422 | }
423 | }
424 | },
425 | "nbformat": 4,
426 | "nbformat_minor": 2
427 | }
428 |
--------------------------------------------------------------------------------
/tutorial/machine_learning/mtters_needing_attention.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "不同数据集比例"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": []
14 | }
15 | ],
16 | "metadata": {
17 | "language_info": {
18 | "name": "python"
19 | },
20 | "orig_nbformat": 4
21 | },
22 | "nbformat": 4,
23 | "nbformat_minor": 2
24 | }
25 |
--------------------------------------------------------------------------------
/tutorial/others/figs/optimization-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/tutorial/others/figs/optimization-1.png
--------------------------------------------------------------------------------
/tutorial/others/figs/optimization-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/tutorial/others/figs/optimization-2.png
--------------------------------------------------------------------------------
/tutorial/others/figs/optimization-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/tutorial/others/figs/optimization-3.png
--------------------------------------------------------------------------------
/tutorial/others/figs/optimization-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/tutorial/others/figs/optimization-4.png
--------------------------------------------------------------------------------
/tutorial/others/figs/optimization-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MabinogiX/dp-tutorial/8a2315ae1c26ba5a4022b2c8229839b524ee225e/tutorial/others/figs/optimization-5.png
--------------------------------------------------------------------------------
/tutorial/others/optimization.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "在机器学习和第一性原理计算的原子/离子relaxation中都涉及到了优化问题,对于机器学习,目标是寻找一组参数使得模型能够完成给定的目标,如给出原子坐标和元素种类后,能得到体系的能量和原子受力。对于原子/离子的relaxation问题,则是优化给定体系中原子/例子的坐标,使得每个原子/离子的受力最小(此时体系能量最低)。\n",
8 | "\n",
9 | "前面这两个例子中都用到了梯度下降法,这篇文章将围绕梯度下降法讲述一些基础概念,这些概念对于机器学习,原子/离子relaxation都有帮助。 \n",
10 | "\n",
11 | "首先看一个最简单的例子:二次函数优化,给定函数$y = x^2$,求函数最小值。这个例子比较简单,可以令函数的导数为0得到答案。但对于复杂的优化问题,我们没有函数的公式,无法求解析解,只能用数值计算求数值解,梯度下降法就是一种常用的数值求解方法。\n",
12 | "\n",
13 | "对于$y = x^2$,可以得到每一点的梯度(导数)公式为:$y = 2x$,然后随便猜一个初值,比如假设x=3这个点y值最小。然后计算得到x=3处的梯度grad = 2 \\* 3 = 6,接下来用下面的公式来更新x的位置:\n",
14 | "$$x_n = x_{n-1} - lr * grad$$\n",
15 | "`lr`可以对应机器学习中的学习率(learning rate),当`lr`设置得到并且n足够大时,我们就能找到$y = x^2$的最小值。下面我们来实现一下这个算法:"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 12,
21 | "metadata": {},
22 | "outputs": [
23 | {
24 | "data": {
25 | "text/plain": [
26 | ""
27 | ]
28 | },
29 | "execution_count": 12,
30 | "metadata": {},
31 | "output_type": "execute_result"
32 | },
33 | {
34 | "data": {
35 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAamklEQVR4nO3df3BVZ5kH8O+T8CvQQtCmuya0DTBSakuXmGzHLR11iNuibVMEtytWcQwFu6sWWE0LuqZpnEpdVErXHSuQuDLL0jLCxrS4UKV2lKrVhGCxpbCFWktSbawELIRf5dk/7g/Ovbk/zs295573Pef7memU3NyE96b3/fbN8z7nPaKqICIic5X4PQAiIsqMQU1EZDgGNRGR4RjURESGY1ATERluhBff9JJLLtHq6movvjURUSB1d3f/SVUrUn3Ok6Curq5GV1eXF9+aiCiQROSVdJ9j6YOIyHAMaiIiwzGoiYgMx6AmIjIcg5qIKF/JZyYV+AwlT7o+hqOjpxerdx5A38AgKsvL0HTTlZhbU+X3sIiIMmtpwaGDR7BwxgL0HTuFygljsHHfZkydNgloaSnIX2HEirqjpxcrt+1D78AgFEDvwCBWbtuHjp5ev4dGRJSeKg4dPIKp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""
38 | ]
39 | },
40 | "metadata": {
41 | "needs_background": "light"
42 | },
43 | "output_type": "display_data"
44 | }
45 | ],
46 | "source": [
47 | "import matplotlib.pyplot as plt\n",
48 | "import numpy as np\n",
49 | "\n",
50 | "def func(x):\n",
51 | " return x * x\n",
52 | "def grad(x):\n",
53 | " return 2 * x\n",
54 | "\n",
55 | "x_guess = 3\n",
56 | "lr = 0.1\n",
57 | "threshold = 0.01\n",
58 | "\n",
59 | "def optimization(x_guess, lr, threshold):\n",
60 | " x = x_guess\n",
61 | " diff = 99999\n",
62 | " y = func(x_guess)\n",
63 | "\n",
64 | " xs = [x_guess]\n",
65 | " ys = [y]\n",
66 | " max_iter = 1000\n",
67 | " while diff > threshold and max_iter > 0:\n",
68 | " x = x - lr * grad(x)\n",
69 | " xs.append(x)\n",
70 | " max_iter -= 1\n",
71 | " if len(xs) > 1:\n",
72 | " # 当当前的x值与上一步x值的距离小于一定值时,认为已经找到了最小值\n",
73 | " diff = abs(xs[-1] - xs[-2])\n",
74 | "\n",
75 | " # 以下代码仅用于画图\n",
76 | " ys.append(func(x))\n",
77 | " return xs, ys\n",
78 | " \n",
79 | "xs, ys = optimization(x_guess, lr, threshold)\n",
80 | "# 以下代码仅用于迭代过程可视化\n",
81 | "x_arr = np.linspace(-3, 3, 100)\n",
82 | "y_arr = [func(x) for x in x_arr]\n",
83 | "plt.scatter(x_arr, y_arr)\n",
84 | "plt.scatter(xs, ys, c='r', marker='x')"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": 26,
90 | "metadata": {},
91 | "outputs": [
92 | {
93 | "name": "stdout",
94 | "output_type": "stream",
95 | "text": [
96 | "iteration number: 21\n"
97 | ]
98 | },
99 | {
100 | "data": {
101 | "text/plain": [
102 | "[0.007130534626283792,\n",
103 | " 0.004563542160821628,\n",
104 | " 0.0029206669829258416,\n",
105 | " 0.0018692268690725384,\n",
106 | " 0.0011963051962064245]"
107 | ]
108 | },
109 | "execution_count": 26,
110 | "metadata": {},
111 | "output_type": "execute_result"
112 | }
113 | ],
114 | "source": [
115 | "print(\"iteration number: {}\".format(len(xs)))\n",
116 | "ys[-5:]"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "上面的代码中使用了$\\left|x_n - x_{n-1}\\right| < threshold$来作为迭代终止的条件(max_iter=1000作为辅助判断条件,防止死循环),可以看到一共迭代了21步,最后5步的值已经非常接近0了,几乎就是正确答案。神经网络训练中最常用的SGD算法,VASP中IBRION=3(steepest descent algorithm, POTIM可以认为是lr)算法归根结底都是上面的梯度下降法。\n",
124 | "\n",
125 | "在神经网络的训练中,当loss不再降低时,认为迭代次数已经足够,模型训练完成;在原子/离子relaxation问题中,当当前步和上一步中energy或者原子受力force差值的绝对值小于一定值时,认为迭代次数已经足够,结构优化完成。"
126 | ]
127 | },
128 | {
129 | "cell_type": "markdown",
130 | "metadata": {},
131 | "source": [
132 | "## 优化过程中的几个重要问题"
133 | ]
134 | },
135 | {
136 | "cell_type": "markdown",
137 | "metadata": {},
138 | "source": [
139 | "### 初猜值问题\n",
140 | "\n",
141 | "数值优化方法(梯度下降法是其中一种方法)都需要一个初始猜测值,并且计算的结果和迭代的次数都依赖初猜值。在$y = x^2$这个问题中,x_guess = 3需要迭代21次,而x_guess = 1只需要迭代16次,好的初始猜测值能明显加速模型收敛。\n",
142 | "\n",
143 | "在神经网络中,模型优化对于初始猜测值不算太敏感,一般使用随机初始化即可(框架可自动完成)。而第一性原理计算对初始猜测值就比较敏感了,细心的同学应该能发现,vasp做结构优化,第一个离子步中电子步的迭代一般都需要几十步,之后电子步迭代次数会明显降低。这就是因为第一个离子步中电子结构初始猜测比较差,需要较多步数才能收敛(注意:电子步的优化方法不是梯度下降,数值优化方法都存在初猜的问题),后面每一个离子步中的电子结构初猜,都使用前一个离子步中已经收敛的电子结构,因此只需少量迭代就能收敛。Guassian的一大优势就是电子初猜很不错,导致需要的迭代次数少于其它同类型软件。\n",
144 | "\n",
145 | "对于原子/离子relaxation同样存在这个问题,不借助工具随手画一个分子结构,将会需要很多离子步才能得到最终构型。但如果先用分子力学MM优化一下构型,作为一个好的初始猜测,再跑第一性原理构型优化,所需的离子步将会显著减少。"
146 | ]
147 | },
148 | {
149 | "cell_type": "markdown",
150 | "metadata": {},
151 | "source": [
152 | "### 局部最小值 vs 全局最小值\n",
153 | "数值优化方法(包括梯度下降法)一般只能找到局部最小值点,而很难或者几乎不可能找到全局最小值点,这导致不同的初猜值甚至可以得到完全不同的结果。\n",
154 | "考虑函数:\n",
155 | "$$y = x^4+x^3-7x^2-x+6$$\n",
156 | "其图像大致如下:\n",
157 | "\n",
158 | "\n",
159 | "\n",
160 | "使用x_guess=-3.5和x_guess=0.5将会得到完全不同的结果,并且前者找到的是全局最小值,而后者只能找到局部最小值。\n",
161 | "\n",
162 | "对于神经网络来说,从实践来看,随机给一个初始猜测,最后训练的模型都差不多,没有显著区别。一种解释认为神经网络参数量太大(上亿参数),里面的极小值点效果都差不多,不一定非要找到全局最小值。\n",
163 | "\n",
164 | "对于第一性原理结构优化来说,不同的初始构型将会得到不同的结果。简单的问题如下图中的乙醇,O上的H原子可以旋转180°作为另一个初猜来做结构优化,最终可以得到两种不同构型的乙醇分子,并且两种结构的energy不一样。\n",
165 | "\n",
166 | "\n",
167 | "\n",
168 | "复杂的问题例如表面催化反应,一般认为反应发生在缺陷处,计算时首先要构建不同的缺陷位点,然后找到表面能最低的那个构型再去计算化学反应。但缺陷位点构型不计其数,基本不可能找到最稳定的构型,只能靠人的经验判断,加上一些简化和假设来做计算。"
169 | ]
170 | },
171 | {
172 | "cell_type": "markdown",
173 | "metadata": {},
174 | "source": [
175 | "### lr值设置\n",
176 | "lr全称learning rate,是个经验性很强的参数。\n",
177 | "\n",
178 | "考虑函数$y = \\left|0.01*x\\right|$,它的导数$y^{\\prime} = 0.01$非常小,如果初猜x_guess=10,那需要迭代1000次才能找到正确结果,增大learning rate能加速收敛。\n",
179 | "\n",
180 | "当learning rate过大时,比如设置为0.9,此时跑$y = \\left|x\\right|$的例子,就会发现迭代进入死循环,数值求解的结果会在正确结果附近反复震荡,永不收敛。"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": null,
186 | "metadata": {},
187 | "outputs": [],
188 | "source": [
189 | "def func(x):\n",
190 | " if x > 0: return x\n",
191 | " else: return -x\n",
192 | "def grad(x):\n",
193 | " if x > 0: return 1\n",
194 | " else: return -1\n",
195 | "lr = 0.9"
196 | ]
197 | },
198 | {
199 | "cell_type": "markdown",
200 | "metadata": {},
201 | "source": [
202 | "\n",
203 | "\n",
204 | "在神经网络的训练中,对于lr设置有大量技巧,一般在训练开始时需要warm-up,即把learning rate从0缓慢增加到指定值,然后在训练过程中逐渐减小learning rate帮助模型收敛。把learning rate的值在整个训练过程中的变化画出来大概是这样子: \n",
205 | " \n",
206 | "设lr=0.1,在训练开始的0-3000步,lr缓慢增长到0.1,然后采用指数(exp)或者sin下降法不断降低lr值,直到训练结束。Deepmd的模型训练就采用了exp下降法,不过没有实现warm-up步骤。 \n",
207 | "另外一种值得一提的lr调节方法是余弦退火法,在训练过程中不断增大lr又再次降低,在一定程度上可以帮助模型跳出局部最小值区域,找到更好的极小值点: \n",
208 | "\n",
209 | "\n",
210 | "总结一下,在神经网络模型训练初期,此时的初猜离真正的结果很远,需要较大的lr值来加速收敛(减小迭代次数),当模型接近真正的结果时,需要降低lr来减少震荡,帮助找到真正的结果。\n",
211 | "\n",
212 | "在VAPS的结构优化中,可以设置`IBRION=3`来启用梯度下降法,然后设置`POTIM`值来调节lr(在vasp中也称为步长),但`POTIM`是固定的,不能逐渐降低。官方文档推荐在构型比较糟糕的情况下,刚开始可以用梯度下降法快速迭代,之后需要换成`IBRION=1`准牛顿法(收敛速度最快)或者`IBRION=2`共轭梯度法(通用性最强)来找到精确解。 \n",
213 | "实际上,梯度下降法是一种收敛速度比较慢的算法,牛顿迭代法/准牛顿迭代法收敛速度远快于梯度下降法,但这两种方法代价很大,特别是牛顿迭代法需要求出体系的Hessian矩阵,对于结构优化只能退而求其次使用准牛顿法,而神经网络模型参数量经常几千万上亿,只能使用梯度下降法来优化。"
214 | ]
215 | }
216 | ],
217 | "metadata": {
218 | "kernelspec": {
219 | "display_name": "Python 3.9.12 ('base')",
220 | "language": "python",
221 | "name": "python3"
222 | },
223 | "language_info": {
224 | "codemirror_mode": {
225 | "name": "ipython",
226 | "version": 3
227 | },
228 | "file_extension": ".py",
229 | "mimetype": "text/x-python",
230 | "name": "python",
231 | "nbconvert_exporter": "python",
232 | "pygments_lexer": "ipython3",
233 | "version": "3.9.12"
234 | },
235 | "orig_nbformat": 4,
236 | "vscode": {
237 | "interpreter": {
238 | "hash": "306f9674966356e6d2017fd9a046da687f90cc683eac906171c3efa96e5922a4"
239 | }
240 | }
241 | },
242 | "nbformat": 4,
243 | "nbformat_minor": 2
244 | }
245 |
--------------------------------------------------------------------------------