feat: add script to generate python scripts from xml#466
Conversation
This will be useful in multiple cases: a) creating python scripts from xml models as starting templates for users b) for llms/agents---where we want them to write python, not xml
[skip ci]
Otherwise we end up with lots of issues related to paths.
WIP, more testing needed
Do not skip if they are default parameters.
[skip-ci]
|
@HengyeZhu: would you have time to review this please? |
|
No problem! I’ll start working on it soon. |
|
Hi @sanjayankur31, Sorry for the delayed reply. This PR may be fine, except for inline-cell cases such as https://github.com/OpenSourceBrain/262670/blob/master/NeuroML2/KC.net.nml. from pyneuroml import pynml
def test_inline_cell_validate():
model = read_neuroml2_file("HH_example_net.nml", include_includes=True)
with tempfile.NamedTemporaryFile("w", dir=".") as f:
write_neuroml2_file(model, f.name)
script = NmlPythonizer(f.name, "temp_nml2py_1").write()[-1]
exec(Path(script).read_text(), {})
assert pynml.validate_neuroml2(Path(f.name).name)With the current code, this fails because the generated Python includes the extracted inline cell as: nml_doc.add("IncludeType", href='hh_cell.cell.nml')while the extracted inline cell file is written to: After generating the extracted-component href relative to the output directory, the test passes. |
Shouldn't the script be run after changing into the The idea is that all the new files are generated in a new folder and must be run there. A few reasons for this:
What do you think? |
I think this is completely fine! I realize why I could not run https://github.com/OpenSourceBrain/262670/blob/master/NeuroML2/KC.net.nml: I was launching it directly from the CLI without setting |
|
Cool, do you think it's OK to merge the PR? |
|
@all-contributors please add @HengyeZhu for code, design, review |
|
I've put up a pull request to add @HengyeZhu! 🎉 |
This will be useful in multiple cases:
a) creating python scripts from xml models as starting templates for users
b) for llms/agents---where we want them to write python, not xml