Skip to content

Devv2#4

Open
Valentyn113 wants to merge 2 commits into
bjorgve:devfrom
Valentyn113:devv2
Open

Devv2#4
Valentyn113 wants to merge 2 commits into
bjorgve:devfrom
Valentyn113:devv2

Conversation

@Valentyn113

Copy link
Copy Markdown

No description provided.

@bjorgve

bjorgve commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Nice work on this, I know it's not easy. Wrapping CompFunction is fiddly and the MRCPP side of it is genuinely confusing, and you got the hard part right: the bindings compile, the D == 3 guards are in the right places, and splitting project_real/project_cplx instead of overloading was the correct call. I built it and tested it locally and it seems to work. A few things to fix before it goes in, and a couple of bigger things I'd like you to think about rather than just patch.

Things to fix

The projectors hang with threads. project_real and project_cplx call your Python function from inside the OpenMP parallel region, and that deadlocks once MRCPP runs on more than one thread, which is the default, so it'll hang on the first call for most people. Build it and try projecting something with the default thread count and you'll see it stall. The existing FunctionTree projectors avoid this by wrapping the call in set_max_threads(1) and restoring it afterwards, so copy that pattern.

A couple of things crash the interpreter outright. CompFunction3D().integrate() segfaults (an empty function with no components, then asking for its integral), and calling .complex() on a real function, or .real() on a complex one, calls abort() and takes the whole kernel down with it. Passing a component index out of range does similar. These should raise a normal Python error, not kill the process. The projector bindings already go out of their way not to crash the kernel, so follow that style: validate the type and index in the accessors, and guard the methods that touch a component before anything's been allocated.

Add tests. There aren't any right now. I tested it on my end and it seems to work, but I'd like you to write them yourself: build it, project a Gaussian, check the integral, exercise add/dot/dagger and the accessors. We need the coverage in the repo regardless.

Rebase and drop the notebooks. You branched before the notebooks PR went in, so the notebook commit here redoes a migration that's already on dev. Rebase onto current dev and drop that commit so this PR is just the CompFunction work.

Run clang-format. There's a .clang-format in the repo and the new code doesn't match it: indentation on the comment blocks, some trailing whitespace.

Things to think about

How it fits with the rest. Right now this is only reachable as vampyr.CompFunction3D and through vampyr.advanced. I haven't had time to properly evaluate this, so I'll leave it to you. Have a look at how the other functions are exposed and think about whether this would be better off looking like the rest of the exposed code rather than sitting off to the side as a separate low-level thing.

How CompFunction is actually meant to be used. This is the important one. I'll be honest, I don't fully understand yet how CompFunction is supposed to be used, and I think working that out is the most valuable thing you can do here. Before we lock down the API, think hard about the real use cases and add an example, ideally a notebook, that shows how someone is meant to use this, alongside the tests. That'll teach us a lot. In particular I expect it'll surface whether we need to give the user a way to set the metric: the apply functions currently hardcode the identity and drop the argument, but the metric is what lets you build a coupled or composite function, so if a real use case needs that, we'll have to expose it. A concrete example is the way to find out. And related to this, the 1D and 2D versions of the class are exposed, but MRCPP hardcodes a lot of the internals to 3D and doesn't really support them, so it may be cleanest to only expose 3D for now. The use-case work will probably confirm that too.

Again, good job getting this working. This is a hard piece and you're most of the way there

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