Hi guys,
Recently I've started using the new Simulation module to help avoid re-invent lots of wheels. But I found that it's not clear how to import my self-defined models without messing with the source code of TeNPy. Does anyone have some suggestions on this?
How to use self-defined model in Simulation's yml file?
-
- Posts: 2
- Joined: 27 Jul 2021, 18:17
Re: How to use self-defined model in Simulation's yml file?
You just need to import the file in python, which contains the model definition; then you can just use the "name" of the model in the simulation parameters. To import that file with the definition, you have two options:
- Either you use the command line option
-1
oftenpy-run
orpython -m tenpy
specifying the module you want to import. Note that this requires the python file with the model to be in PYTHONPATH. - You can use a small wrapper python script that imports the corresponding file, and then calls tenpy.console_main or tenpy.run_simulation as a python function, depending on whether you want to parse command line arguments yourself or not.
So the total wrapper script can be as simple asIf it is in the same folder asCode: Select all
import my_model_definitions if __name__ == "__main__": import tenpy tenpy.console_main()
my_model_definitions.py
, you can then call it aspython tenpy_wrapper.py my_config.yml
If you want, you could even add thetenpy.console_main()
at the end of the model file to make that executable.
-
- Posts: 2
- Joined: 27 Jul 2021, 18:17
Re: How to use self-defined model in Simulation's yml file?
Thanks a lot! I will try it outJohannes wrote: ↑11 Aug 2021, 17:14 You just need to import the file in python, which contains the model definition; then you can just use the "name" of the model in the simulation parameters. To import that file with the definition, you have two options:
- Either you use the command line option
-1
oftenpy-run
orpython -m tenpy
specifying the module you want to import. Note that this requires the python file with the model to be in PYTHONPATH.- You can use a small wrapper python script that imports the corresponding file, and then calls tenpy.console_main or tenpy.run_simulation as a python function, depending on whether you want to parse command line arguments yourself or not.
So the total wrapper script can be as simple asIf it is in the same folder asCode: Select all
import my_model_definitions if __name__ == "__main__": import tenpy tenpy.console_main()
my_model_definitions.py
, you can then call it aspython tenpy_wrapper.py my_config.yml
If you want, you could even add thetenpy.console_main()
at the end of the model file to make that executable.