antoinefalisse / opensimAD

Libraries for OpenSimAD - OpenSim with support for Algorithmic Differentiation
Apache License 2.0
18 stars 11 forks source link

Error: cannot unpack non-iterable NoneType object #15

Closed Minh309 closed 1 year ago

Minh309 commented 1 year ago

Hi,

I am trying the code to generate some external functions in Linux for the models being used in this project: https://github.com/antoinefalisse/predictsim_mtp

It seems some models can work but others cannot. For example, when it comes to model: new_model_noMTP_scaled_FK.osim from predictsim_mtp\OpenSimModel\new_model\Model The code cannot generate the external functions with the following error:

terminate called after throwing an instance of 'std::runtime_error' what(): Needs to be symbolic make[2]: *** [CMakeFiles/new_model_noMTP_scaled_FK.dir/build.make:103: new_model_noMTP_scaled_FK] Aborted make[2]: *** Deleting file 'new_model_noMTP_scaled_FK' make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/new_model_noMTP_scaled_FK.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 Traceback (most recent call last): File "main.py", line 55, in <module> generateExternalFunction(pathOpenSimModel, pathExample, pathID, File "/home/minht/OpenSim_External/opensimAD/utilities.py", line 560, in generateExternalFunction buildExternalFunction(outputFilename, outputDir, 3*nCoordinates, File "/home/minht/OpenSim_External/opensimAD/utilities.py", line 745, in buildExternalFunction generateF(nInputs) File "/home/minht/OpenSim_External/opensimAD/utilities.py", line 658, in generateF y,_,_ = foo.foo(arg) TypeError: cannot unpack non-iterable NoneType object

I hope you could solve this issue.

antoinefalisse commented 1 year ago

@Minh309 thanks for reporting, I will take a look asap. Btw, please consider using this repo for the predictive simulations: https://github.com/antoinefalisse/predsim_tutorial it is more up to date.

Minh309 commented 1 year ago

Hi Antoine, Thanks a lot for your reply. Correct me if I am wrong but can this code generate all external functions used in your predictive simulation projects? And we just need to change the model as an input to generate the external library?

antoinefalisse commented 1 year ago

Yes, that's the idea, but I developed this code afterwards so I am not sure about backward compatibility. This predictive simulation project is the most up to date: https://github.com/antoinefalisse/predsim_tutorial and you should be able to use the external functions generated using this code.

Here are some instructions I sent to someone:

  1. Download https://github.com/antoinefalisse/opensimAD
  2. Download https://github.com/antoinefalisse/predsim_tutorial
  3. Let’s generate all we need for the model Hamner_modified_scaled.osim in predsim_tutorial\OpenSimModel\Hamner_modified a. Copy Hamner_modified_scaled.osim in opensimAD\examples b. Change the path here so that you point to the right model, so basically you should here have 'Hamner_modified_scaled.osim' instead of 'Hamner_modified.osim' c. Run opensimAD\main.py (you will need to install some packages, there should be some instructions) d. You should get a bunch of files in opensimAD\examples i. Hamner_modified_scaled.cpp ii. Hamner_modified_scaled.dll iii. Hamner_modified_scaled_map.npy e. Create a folder name ExternalFunction under predsim_tutorial\OpenSimModel\Hamner_modified\Model (the folder is already there, I just make you reproduce the procedure in case you want to play with a different model) f. Copy the three files from d. in that folder (there are already there, I just make you reproduce the procedure in case you want to play with a different model)
  4. Now you can run simulations with the new model a. Set your case in the settings in predsim_tutorial\settings.py i. Cases 0 and 1 points to the right model b. Run main.py and make sure you run the case you set in a. https://github.com/antoinefalisse/predsim_tutorial/blob/main/main.py#L51 i. Case 1 converged in 635 iterations on my windows machine (case 0 in 704 iterations). It will differ in mac or linux. If my notes are right, Case 1 converged in 597 iterations on my linux machine c. You can plot the results using the plotResults.py function

Let me know for questions.

Minh309 commented 1 year ago

Hi Antoine,

Thank you so much for your thorough instructions. I managed to run the code in Linux. Now I have another question to ask: Is this code compatible with any OpenSim models or just with your model? If so, can we just use normal scale function in OpenSim to generate the model and use it in this code? If not, where should be modified to work with this code?

Thank you! Minh

antoinefalisse commented 1 year ago

Hi Minh,

The code to generate the external function should work with most opensim models, but not all. Please submit an issue if it does not work and I can check whether that would be easy to support. If you have a particular model you want to try, you can send it over too. Any scaled version of the example models should work.

The predictive simulation code is quite specific to the model, but you can adjust it for another model.

Let me know for questions,