CLion configuration for Catalyst (or alternative IDE)

I have a couple of basic questions regarding developing for Catalyst.

  1. Is there anybody here using CLion as IDE? If so, would you mind sharing how you work with the Catalyst project?
  2. Otherwise, may you tell me what IDE do you use for development? And if you can easily open and build Catalyst from there?

My experience from CLion:

  • I open the project from a Catalyst checkout.

  • I cannot access the project’s symbols, i.e., navigate to variable and function declarations.
    I understand this can be a little bit more complex since Catalyst uses git submodules, e.g., llvm-project.

  • I cannot configure and build from the IDE.
    As an example of errors I get:

    Couldn’t parse command line: ‘cmake -G Ninja -B /home/rturrado/Projects/catalyst/frontend/catalyst/third_party/oqc/src//build -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DRUNTIME_BUILD_DIR=/home/rturrado/Projects/catalyst/frontend/catalyst/third_party/oqc/src//../../../../../runtime/build -DPython_EXECUTABLE=/home/rturrado/Projects/catalyst/venv/bin/python3’
    No input file specified

    While I don’t see anything really wrong with the Toolchain (default, /usr/bin/make, clang, clang++, lldb) or the Makefile (build target = all, clean target = clean) configurations.

  • I also have build problems after updating a working branch.
    I would say they are due to doing git pull on the root directory, then other projects than Catalyst, e.g., Enzyme, llvm-project, or mlir-hlo, getting updated as well, and Catalyst not compiling with those new versions of Enzyme and so on… Could that be?

Many thanks!
Roberto.

Hi @rturrado ,

Our PennyLane developers generally use VSCode. IDE integration is not something we support so unfortunately I can’t really provide any guidance regarding CLion. My recommendation would be to use VSCode if possible.

Let me know if that works for you!

1 Like

Hi @CatalinaAlbornoz ,

Many thanks for your answer. I understand you don’t provide support for this.

However, I have finally managed to use CLion as IDE, so I will leave here a few tips for future developers in the same situation.

  1. Follow the installation instructions to build a Catalyst checkout. make all should generate a catalyst/mlir/build/compile_commands.json output file.
  2. Open that file from a Catalyst checkout root directory with clion ./mlir/build/compile_commands.json &. Or, after launching CLion, e.g., clion &, go to File > Open, browse to catalyst/mlir/build, open compile_commands.json, and, when asked, choose Open as Project.
  3. If you don’t see the catalyst folder as the root of the Project tool, go to Tools > Compilation Database > Change Project Root, browse to the catalyst folder, and select it. By this point, indexing should already be working, e.g., you should be able to CTRL + click on a symbol and go to its definition, even for code in mlir/llvm-project/llvm/include.
  4. If you don’t see the Make tool, go to View > Tool Windows > make. The Make tool lists all the possible make targets (e.g., all, clean…). Running one of them should automatically add it to the Run/Debug configurations.
  5. In order to run a Custom Build Application (e.g., quantum-opt):
    1. Go to Run > Edit Configurations.
    2. Add a Custom Build Application.
    3. Fill the different entries (e.g., Name=quantum-opt, Executable=<your Catalyst root folder>/mlir/build/bin/quantum-opt, Program arguments=–pass-pipeline=“builtin.module(merge-rotations)” --split-input-file -verify-diagnostics ./mlir/test//Quantum/MergeRotationsTest.mlir, Working directory=<your Catalyst root folder>).
      For Target, what I’ve done is to create different Custom Build Targets, e.g., build_with_make_dialects, build_with_make_clean, and point each of those to an External Tool (in this case, they are basically calling /usr/bin/make with a dialects or clean argument, respectively).

Troubleshooting:

  • If indexing doesn’t work after step 3 above, try File > Invalidate Caches and restarting the IDE.

Hi @rturrado

Thanks for sharing your findings.

Out of curiosity, would a single unified top-level CMake structure with the individual submodules (frontend, mlir, runtime) being part of it be useful for you here? This isn’t a high priority item for us right now, but we are considering the need for this if there is utility in it.

Hi @mlxd ,

I am not really sure. My experience with IDEs, and more concretely with CLion, is that it can take sometime to properly configure them to work with a given codebase. Actually, indexing is something that I find tipically problematic, so when I opened the project as a Compilation Database, and I could start navigating everywhere, it looked like everything was already fine! Honestly, I could not say how CLion would behave with a CMake Catalyst project.

A couple of points regarding Catalyst build system, if you may allow me, although please notice that I am not an expert in build systems!

  • I have noticed that the build of Catalyst can be extremely fast, so that’s a big point not to touch many things.
  • I would personally have found a project with a top CMakeLists.txt a more modern setup.
  • Even more personally, I would give it a go to the idea of replacing git submodules with something like CMake’s FetchContent or, if possible, by using a package manager such as bazel or conan. But this should mean some work.

Thanks!

Thanks for sharing this feedback @rturrado ! :folded_hands:

1 Like