1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// MIT License
// Copyright 2023--present rgpot developers
//
// Auto-generated by cbindgen — do not edit manually.
/* Generated with cbindgen:0.27.0 */
/* Warning: this file is auto-generated by cbindgen. Do not modify this manually. */
/**
* Status codes returned by all C API functions.
*/
typedef enum rgpot_status_t rgpot_status_t;
/**
* Opaque potential handle wrapping a callback + user data.
*/
typedef struct PotentialImpl PotentialImpl;
/**
* RPC client that connects to a remote rgpot server.
*/
typedef struct RpcClient RpcClient;
/**
* Input configuration for a potential energy evaluation.
*
* All tensor fields are *borrowed* — the caller retains ownership and must
* keep them alive for the lifetime of this struct.
*
* # Example (from C)
*
* ```c
* double positions[] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0};
* int types[] = {1, 1};
* double cell[] = {10.0,0,0, 0,10.0,0, 0,0,10.0};
*
* rgpot_force_input_t input = rgpot_force_input_create(2, positions, types, cell);
* // ... use input ...
* rgpot_force_input_free(&input);
* ```
*/
typedef struct rgpot_force_input_t rgpot_force_input_t;
/**
* Results from a potential energy evaluation.
*
* The `forces` field starts as `NULL` and is set by the potential callback to
* a callee-allocated DLPack tensor. After the call, the caller owns the
* tensor and must free it via `rgpot_tensor_free`.
*
* # Fields
*
* - `forces`: output force tensor, same shape/dtype as `positions`.
* - `energy`: the calculated potential energy.
* - `variance`: uncertainty estimate; zero when not applicable.
*/
typedef struct rgpot_force_out_t rgpot_force_out_t;
/**
* Opaque handle exposed to C as `rgpot_potential_t`.
*
* This is a type alias used by cbindgen to generate a forward declaration.
*/
typedef struct PotentialImpl rgpot_potential_t;
/**
* Function pointer type for a potential energy calculation.
*
* The callback receives:
* - `user_data`: opaque pointer to the C++ object (e.g. `LJPot*`)
* - `input`: the atomic configuration (DLPack tensors)
* - `output`: the buffer for results (callback sets `forces` tensor)
*
* Returns `RGPOT_SUCCESS` on success, or an error status code.
*/
typedef enum ;
/**
* Opaque RPC client handle.
*/
typedef struct RpcClient rgpot_rpc_client_t;
/**
* Create a non-owning 2-D f64 tensor on CPU wrapping an existing buffer.
*
* The returned tensor borrows `data` — the caller must keep `data` alive
* for the lifetime of the tensor. Call `rgpot_tensor_free` when done.
*
* # Safety
* `data` must point to at least `rows * cols` contiguous `f64` values.
*/
DLManagedTensorVersioned *;
/**
* Create a non-owning 1-D i32 tensor on CPU wrapping an existing buffer.
*
* # Safety
* `data` must point to at least `len` contiguous `c_int` values.
*/
DLManagedTensorVersioned *;
/**
* Create a non-owning 2-D f64 tensor on CPU for a 3x3 matrix.
*
* Convenience wrapper — equivalent to `rgpot_tensor_cpu_f64_2d(data, 3, 3)`.
*
* # Safety
* `data` must point to at least 9 contiguous `f64` values.
*/
DLManagedTensorVersioned *;
/**
* Create an **owning** 2-D f64 tensor on CPU by copying data.
*
* The returned tensor owns a copy of the data — the caller may free the
* original buffer after this call. Call `rgpot_tensor_free` when done.
*
* # Safety
* `data` must point to at least `rows * cols` contiguous `f64` values.
*/
DLManagedTensorVersioned *;
/**
* Free a DLPack tensor by invoking its deleter.
*
* If `tensor` is `NULL`, this is a no-op.
*
* # Safety
* `tensor` must have been obtained from one of the `rgpot_tensor_*` creation
* functions, or be a valid `DLManagedTensorVersioned` with a deleter.
*/
void ;
/**
* Get the device of a DLPack tensor.
*
* # Safety
* `tensor` must be a valid, non-null `DLManagedTensorVersioned*`.
*/
DLDevice ;
/**
* Get the raw data pointer of a DLPack tensor.
*
* # Safety
* `tensor` must be a valid, non-null `DLManagedTensorVersioned*`.
*/
const void *;
/**
* Get the shape array and number of dimensions of a DLPack tensor.
*
* Writes the number of dimensions to `*ndim_out` and returns a pointer to
* the shape array (length `*ndim_out`).
*
* # Safety
* Both `tensor` and `ndim_out` must be valid, non-null pointers.
*/
const int64_t *;
/**
* Retrieve a pointer to the last error message for the current thread.
*
* The pointer is valid until the next call to any `rgpot_*` function
* on the same thread.
*
* # Safety
* This is intended to be called from C. The returned pointer must not
* be freed by the caller.
*/
const char *;
/**
* Create a `rgpot_force_input_t` from raw CPU arrays.
*
* Internally creates non-owning DLPack tensors wrapping the raw pointers.
* The caller must call `rgpot_force_input_free` to free the tensor metadata
* when done (this does NOT free the underlying data arrays).
*
* # Safety
* All pointers must be valid for the lifetime of the returned struct.
* `pos` must point to at least `n_atoms * 3` doubles.
* `atmnrs` must point to at least `n_atoms` ints.
* `box_` must point to at least 9 doubles.
*/
struct rgpot_force_input_t ;
/**
* Free the DLPack tensor metadata in a `rgpot_force_input_t`.
*
* This frees the `DLManagedTensorVersioned` wrappers created by
* `rgpot_force_input_create`, but does NOT free the underlying data arrays
* (which are borrowed).
*
* After this call, all tensor pointers in `input` are set to NULL.
*
* If `input` is NULL, this is a no-op.
*
* # Safety
* `input` must be NULL or point to a valid `rgpot_force_input_t` whose
* tensors were created by `rgpot_force_input_create`.
*/
void ;
/**
* Create a `rgpot_force_out_t` with null forces and zeroed scalars.
*
* The `forces` field starts as NULL — the potential callback is responsible
* for setting it to a valid DLPack tensor.
*/
struct rgpot_force_out_t ;
/**
* Create a new potential handle from a callback function pointer.
*
* - `callback`: the function that performs the force/energy calculation.
* - `user_data`: opaque pointer forwarded to every callback invocation
* (typically a pointer to the C++ potential object).
* - `free_fn`: optional destructor for `user_data`. Pass `NULL` if the
* caller manages the lifetime externally.
*
* Returns a heap-allocated `rgpot_potential_t*`, or `NULL` on failure.
* The caller must eventually pass the returned pointer to
* `rgpot_potential_free`.
*/
rgpot_potential_t *;
/**
* Perform a force/energy calculation using the potential handle.
*
* - `pot`: a valid handle obtained from `rgpot_potential_new`.
* - `input`: pointer to the input configuration (DLPack tensors).
* - `output`: pointer to the output struct. The callback sets `output->forces`
* to a callee-allocated DLPack tensor.
*
* Returns `RGPOT_SUCCESS` on success, or an error status code.
* On error, call `rgpot_last_error()` for details.
*/
enum rgpot_status_t ;
/**
* Free a potential handle previously obtained from `rgpot_potential_new`.
*
* If `pot` is `NULL`, this function is a no-op.
* After this call, `pot` must not be used again.
*/
void ;
/**
* Create a new RPC client connected to `host:port`.
*
* Returns a heap-allocated handle, or `NULL` on failure.
* The caller must eventually call `rgpot_rpc_client_free`.
*/
rgpot_rpc_client_t *;
/**
* Perform a remote force/energy calculation.
*
* Returns `RGPOT_SUCCESS` on success, or an error status code.
*/
enum rgpot_status_t ;
/**
* Free an RPC client handle.
*
* If `client` is `NULL`, this is a no-op.
*/
void ;
/**
* Start an RPC server listening on `host:port`, dispatching to `pot`.
*
* This function blocks the current thread. It creates its own tokio runtime.
*
* # Safety
* `pot` must be a valid pointer obtained from `rgpot_potential_new`.
* The potential and its user_data must remain valid for the lifetime
* of the server.
*/
enum rgpot_status_t ;
/* RGPOT_H */