Skip to content

new tutorials for C api - #320

Merged
Luthaf merged 2 commits into
metatensor:metatomic-corefrom
EricBoittier:repairHistory
Sep 17, 2026
Merged

Luthaf merged 2 commits into
metatensor:metatomic-corefrom
EricBoittier:repairHistory

Conversation

@EricBoittier

@EricBoittier EricBoittier commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Adds additional examples/tutorials to the C api section
these changes should go on top of #313 and the hot fix for MSVC (the windows C/C++ compiler)

Contributor (creator of pull-request) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

@Luthaf Luthaf mentioned this pull request Sep 8, 2026
3 of 4 tasks
@EricBoittier
EricBoittier marked this pull request as ready for review September 10, 2026 11:52
@EricBoittier
EricBoittier marked this pull request as draft September 10, 2026 11:52
@EricBoittier
EricBoittier marked this pull request as ready for review September 10, 2026 12:56
@EricBoittier
EricBoittier force-pushed the repairHistory branch 2 times, most recently from 947dec7 to 32a2662 Compare September 10, 2026 14:43

@Luthaf Luthaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this needs a bit more cleanup/organization before I can have a detailed look.

A lot of the prose still reads as LLM-generated and should be rewritten with your own words. Most tutorials would also benefit from having more comments and smaller blobs of code.

There are also a couple of tutorials I'm not sure are pulling their weight; mainly the symd one and the string/error/units one.

Comment thread examples/c/3-add-model.c Outdated
Comment thread docs/src/_include/metatomic_force.c Outdated
Comment thread examples/c/4-strings-errors-units.c Outdated
@Luthaf

Luthaf commented Sep 14, 2026

Copy link
Copy Markdown
Member

This should also be rebased on top of metatomic-core, not main =)

@EricBoittier
EricBoittier force-pushed the repairHistory branch 3 times, most recently from 5d51d81 to 57a6659 Compare September 14, 2026 13:10
@EricBoittier

Copy link
Copy Markdown
Contributor Author

So this needs a bit more cleanup/organization before I can have a detailed look.

A lot of the prose still reads as LLM-generated and should be rewritten with your own words. Most tutorials would also benefit from having more comments and smaller blobs of code.

There are also a couple of tutorials I'm not sure are pulling their weight; mainly the symd one and the string/error/units one.

Thanks! I cleaned up the tutorial (LLM slop, temporary files, other garbage) and rebased/squashed into 1 commit

Comment thread examples/c/1-create-system.c
Comment thread examples/c/2-using-system.c
Comment thread examples/c/3-add-model.c Outdated
Comment thread examples/c/3-add-model.c Outdated
Comment thread examples/c/3-add-model.c Outdated
Comment thread examples/c/4-add-plugin.c Outdated
Comment thread examples/c/4-add-plugin.c Outdated
Comment thread examples/c/4-add-plugin.c Outdated
Comment thread examples/c/4-add-plugin.c Outdated
Comment thread examples/c/4-add-plugin.c Outdated
deleted old files, and reordered examples
del old file
Refactor C API tutorials (clean slop)
includes refining comments, enhancing explanations of DLPack tensor usage, and restructuring the tutorial flow for better understanding.
typo - and some expected output

Enhance C API tutorials with improved explanations and structure
Refactor the examples to clarify the integration of DLPack tensors with existing simulation data. Update comments for better understanding of tensor creation and usage, and streamline the tutorial flow. Additionally, ensure consistency in terminology and enhance the overall readability of the code.

Add inclusion of `<inttypes.h>` in `3-add-model.c` for consistent usage of PRIx64 across examples
Comment thread examples/c/4-plugin.c
Comment thread docs/src/conf.py
build_doxygen_docs()
generate_examples()

app.connect("builder-inited", add_extra_files_to_zips, priority=600)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

600 is a magic number, or is there some rule to this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is above the default priority of 500 (which is used by sphinx-gallery), to make sure we run after it generated the initial zip

Comment thread examples/c/utils/dlpack.h

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider making this it's own example? seems like it would be useful to others

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already mostly a copy of the code in the first tutprial

int64_t* shape;
int64_t* strides;
} CustomDLPackContext;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that's a lot cleaner

struct mts_array_t prop_array = make_mts_array(
distance_values, 2, (uintptr_t[]){1, 1},
(DLDataType){.code = kDLInt, .bits = 32, .lanes = 1}, 1
distance_values, (uintptr_t[]){1, 1}, 2, i32_dtype

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much cleaner

Comment thread examples/c/4-plugin.c

// %%
//
// A minimal model

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@EricBoittier EricBoittier left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done. Tutorial 4 reads much better now, too.

- add helpers in utils/, included in zip
- simplify parts of the code
- add a bunch of explanations

@EricBoittier EricBoittier left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Luthaf
Luthaf merged commit 96d2432 into metatensor:metatomic-core Sep 17, 2026
78 checks passed
EricBoittier added a commit to EricBoittier/metatomic that referenced this pull request Sep 25, 2026
Co-authored-by: Guillaume Fraux <guillaume.fraux@epfl.ch>
Luthaf added a commit that referenced this pull request Sep 29, 2026
Co-authored-by: Guillaume Fraux <guillaume.fraux@epfl.ch>
Luthaf added a commit that referenced this pull request Sep 29, 2026
Co-authored-by: Guillaume Fraux <guillaume.fraux@epfl.ch>
Luthaf added a commit that referenced this pull request Sep 30, 2026
Co-authored-by: Guillaume Fraux <guillaume.fraux@epfl.ch>
Luthaf added a commit that referenced this pull request Oct 1, 2026
Co-authored-by: Guillaume Fraux <guillaume.fraux@epfl.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants