Hybrid Jax Model: JIT gradient computation error

Hello there,

I have an Issue with the jit computation if gradients in a (in principle) hybrid model using Jax and Catalyst. The following ends up with an error regarding the compiler (I guess).

Is there some advice what I can do about this?

Best regards

minn-bj

Code:

import pennylane as qml
from jax import numpy as np

import catalyst

# Hyperparameters
compiler="catalyst"
device="lightning.kokkos"
n_wires = 22

# Sample
data = qml.numpy.random.rand(n_wires)

# Weights
weights = np.ones([n_wires])

# Device
dev = qml.device(device, wires=n_wires)

# Quantum circuit
@qml.qnode(dev, interface="jax", diff_method="adjoint")
def circuit(data, weights):

    for i in range(n_wires):
        qml.RY(data[i], wires=i)
        qml.RX(weights[i], wires=i)
    
    return [qml.expval(qml.PauliZ(i)) for i in range(n_wires)]

# JIT circuit
circuit = qml.qjit(circuit, compiler=compiler)

# Loss
def loss_fn(weights, data):
    predictions = np.array(circuit(data, weights))
    loss = np.average((data - predictions) ** 2)
    return loss

# Loss Gradient
grad = qml.qjit(catalyst.grad(loss_fn, method="auto"))

# Compute Grad
print(grad(weights, data))

Some more information about the system (sorry for the format):

Name: pennylane Version: 0.43.0 Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network. Home-page: Author: Author-email: License: Location: [/opt/conda/lib/python3.11/site-packages](https://vscode-remote+qcokain-002eintra-002edlr-002ede.vscode-resource.vscode-cdn.net/opt/conda/lib/python3.11/site-packages) Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing_extensions Required-by: pennylane_catalyst, pennylane_lightning, pennylane_lightning_gpu, pennylane_lightning_kokkos Platform info: Linux-5.15.0-151-generic-x86_64-with-glibc2.35 Python version: 3.11.10 Numpy version: 2.4.0 Scipy version: 1.16.3 JAX version: 0.6.2 Installed devices: - nvidia.custatevec (pennylane_catalyst-0.13.0) - nvidia.cutensornet (pennylane_catalyst-0.13.0) - oqc.cloud (pennylane_catalyst-0.13.0) - softwareq.qpp (pennylane_catalyst-0.13.0) - lightning.qubit (pennylane_lightning-0.43.0) - default.clifford (pennylane-0.43.0) - default.gaussian (pennylane-0.43.0) - default.mixed (pennylane-0.43.0) - default.qubit (pennylane-0.43.0) - default.qutrit (pennylane-0.43.0) - default.qutrit.mixed (pennylane-0.43.0) - default.tensor (pennylane-0.43.0) - null.qubit (pennylane-0.43.0) - reference.qubit (pennylane-0.43.0) - lightning.gpu (pennylane_lightning_gpu-0.43.0) - lightning.kokkos (pennylane_lightning_kokkos-0.43.0)

Error msg:


CalledProcessError                        Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:448, in Compiler.run_from_ir(self, ir, module_name, workspace)
447     print(f"\[SYSTEM\] {’ '.join(cmd)}", file=self.options.logfile)
 → 448 result = subprocess.run(cmd, check=True, capture_output=True, text=True)
449 if self.options.verbose or os.getenv(“ENABLE_DIAGNOSTICS”):

File /opt/conda/lib/python3.11/subprocess.py:571, in run(input, capture_output, timeout, check, \*popenargs, \*\*kwargs)
570     if check and retcode:
 → 571         raise CalledProcessError(retcode, process.args,
572                                  output=stdout, stderr=stderr)
573 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command ‘\[’/opt/conda/bin/catalyst’, ‘-o’, ‘/tmp/grad.loss_fnbi25h3bs/grad.loss_fn.ll’, ‘–module-name’, ‘grad.loss_fn’, ‘–workspace’, ‘/tmp/grad.loss_fnbi25h3bs’, ‘-verify-each=false’, ‘–catalyst-pipeline’, ‘EnforceRuntimeInvariantsPass(split-multiple-tapes;builtin.module(apply-transform-sequence);inline-nested-module),HLOLoweringPass(canonicalize;func.func(chlo-legalize-to-stablehlo);func.func(stablehlo-legalize-control-flow);func.func(stablehlo-aggressive-simplification);stablehlo-legalize-to-linalg;func.func(stablehlo-legalize-to-std);func.func(stablehlo-legalize-sort);stablehlo-convert-to-signless;canonicalize;scatter-lowering;hlo-custom-call-lowering;cse;func.func(linalg-detensorize{aggressive-mode});detensorize-scf;detensorize-function-boundary;canonicalize;symbol-dce),QuantumCompilationPass(annotate-function;lower-mitigation;lower-gradients;adjoint-lowering),BufferizationPass(inline;convert-tensor-to-linalg;convert-elementwise-to-linalg;gradient-preprocess;one-shot-bufferize{bufferize-function-boundaries         allow-return-allocs-from-loops         function-boundary-type-conversion=identity-layout-map         unknown-type-conversion=identity-layout-map};canonicalize;gradient-postprocess;func.func(buffer-hoisting);func.func(buffer-loop-hoisting);func.func(promote-buffers-to-stack);func.func(buffer-deallocation);convert-arraylist-to-memref;convert-bufferization-to-memref;canonicalize;cp-global-memref),MLIRToLLVMDialect(expand-realloc;convert-gradient-to-llvm;memrefcpy-to-linalgcpy;func.func(convert-linalg-to-loops);convert-scf-to-cf;expand-strided-metadata;lower-affine;arith-expand;convert-complex-to-standard;convert-complex-to-llvm;convert-math-to-llvm;convert-math-to-libm;convert-arith-to-llvm;memref-to-llvm-tbaa;finalize-memref-to-llvm{use-generic-functions};convert-index-to-llvm;convert-catalyst-to-llvm;convert-quantum-to-llvm;emit-catalyst-py-interface;canonicalize;reconcile-unrealized-casts;gep-inbounds;register-inactive-callback),’, ‘/tmp/grad.loss_fnbi25h3bs/tmp76lhqb8r.mlir’\]’ died with <Signals.SIGABRT: 6>.

The above exception was the direct cause of the following exception:

CompileError                              Traceback (most recent call last)
Cell In\[5\], line 42
39 grad = qml.qjit(catalyst.grad(loss_fn,  method=“auto”))
41 # Compute Grad
—> 42 print(grad(weights, data))

File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(\*args, \*\*kwargs)
54     s_caller = “::L”.join(
55         \[str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)\[1\]\[1:3\]\]
56     )
57     lgr.debug(
58         f"Calling {f_string} from {s_caller}",
59         \*\*\_debug_log_kwargs,
60     )
—> 61 return func(\*args, \*\*kwargs)

File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:590, in QJIT.**call**(self, \*args, \*\*kwargs)
586         kwargs = {“static_argnums”: self.compile_options.static_argnums, \*\*kwargs}
588     return self.user_function(\*args, \*\*kwargs)
 → 590 requires_promotion = self.jit_compile(args, \*\*kwargs)
592 # If we receive tracers as input, dispatch to the JAX integration.
593 if any(isinstance(arg, jax.core.Tracer) for arg in tree_flatten(args)\[0\]):

File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(\*args, \*\*kwargs)
54     s_caller = “::L”.join(
55         \[str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)\[1\]\[1:3\]\]
56     )
57     lgr.debug(
58         f"Calling {f_string} from {s_caller}",
59         \*\*\_debug_log_kwargs,
60     )
—> 61 return func(\*args, \*\*kwargs)

File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:666, in QJIT.jit_compile(self, args, \*\*kwargs)
663     self.jaxpr, self.out_type, self.out_treedef, self.c_sig = self.capture(args, \*\*kwargs)
665     self.mlir_module = self.generate_ir()
 → 666     self.compiled_function, \_ = self.compile()
668     self.fn_cache.insert(self.compiled_function, args, self.out_treedef, self.workspace)
670 elif self.compiled_function is not cached_fn.compiled_fn:
671     # Restore active state from cache.

File /opt/conda/lib/python3.11/site-packages/catalyst/debug/instruments.py:145, in instrument..wrapper(\*args, \*\*kwargs)
142 @functools.wraps(fn)
143 def wrapper(\*args, \*\*kwargs):
144     if not InstrumentSession.active:
 → 145         return fn(\*args, \*\*kwargs)
147     with ResultReporter(stage_name, has_finegrained) as reporter:
148         self = args\[0\]

File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(\*args, \*\*kwargs)
54     s_caller = “::L”.join(
55         \[str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)\[1\]\[1:3\]\]
56     )
57     lgr.debug(
58         f"Calling {f_string} from {s_caller}",
59         \*\*\_debug_log_kwargs,
60     )
—> 61 return func(\*args, \*\*kwargs)

File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:816, in QJIT.compile(self)
810     shared_object, llvm_ir = self.compiler.run_from_ir(
811         self.overwrite_ir,
812         str(self.mlir_module.operation.attributes\[“sym_name”\]).replace(‘"’, “”),
813         self.workspace,
814     )
815 else:
 → 816     shared_object, llvm_ir = self.compiler.run(self.mlir_module, self.workspace)
818 compiled_fn = CompiledFunction(
819     shared_object, func_name, restype, self.out_type, self.compile_options
820 )
822 return compiled_fn, llvm_ir

File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(\*args, \*\*kwargs)
54     s_caller = “::L”.join(
55         \[str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)\[1\]\[1:3\]\]
56     )
57     lgr.debug(
58         f"Calling {f_string} from {s_caller}",
59         \*\*\_debug_log_kwargs,
60     )
—> 61 return func(\*args, \*\*kwargs)

File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:522, in Compiler.run(self, mlir_module, \*args, \*\*kwargs)
519     compiler = PythonCompiler()
520     mlir_module = compiler.run(mlir_module)
 → 522 return self.run_from_ir(
523     mlir_module.operation.get_asm(
524         binary=False, print_generic_op_form=False, assume_verified=True
525     ),
526     str(mlir_module.operation.attributes\[“sym_name”\]).replace(‘"’, “”),
527     \*args,
528     \*\*kwargs,
529 )

File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(\*args, \*\*kwargs)
54     s_caller = “::L”.join(
55         \[str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)\[1\]\[1:3\]\]
56     )
57     lgr.debug(
58         f"Calling {f_string} from {s_caller}",
59         \*\*\_debug_log_kwargs,
60     )
—> 61 return func(\*args, \*\*kwargs)

File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:455, in Compiler.run_from_ir(self, ir, module_name, workspace)
453             print(result.stderr.strip(), file=self.options.logfile)
454 except subprocess.CalledProcessError as e:  # pragma: nocover
 → 455     raise CompileError(f"catalyst failed with error code {e.returncode}: {e.stderr}") from e
457 if os.path.exists(output_ir_name):
458     with open(output_ir_name, “r”, encoding=“utf-8”) as f:

CompileError: catalyst failed with error code -6: catalyst: /\__w/catalyst/catalyst/mlir/lib/Gradient/Transforms/ConversionPatterns.cpp:225: virtual llvm::LogicalResult {anonymous}::AdjointOpPattern::matchAndRewrite(catalyst::gradient::AdjointOp, catalyst::gradient::AdjointOpAdaptor, mlir::ConversionPatternRewriter&) const: Assertion `callee && callee.getNumResults() == 2 && "invalid qfunc symbol in adjoint op"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0.	Program arguments: /opt/conda/bin/catalyst -o /tmp/grad.loss_fnbi25h3bs/grad.loss_fn.ll --module-name grad.loss_fn --workspace /tmp/grad.loss_fnbi25h3bs -verify-each=false --catalyst-pipeline "EnforceRuntimeInvariantsPass(split-multiple-tapes;builtin.module(apply-transform-sequence);inline-nested-module),HLOLoweringPass(canonicalize;func.func(chlo-legalize-to-stablehlo);func.func(stablehlo-legalize-control-flow);func.func(stablehlo-aggressive-simplification);stablehlo-legalize-to-linalg;func.func(stablehlo-legalize-to-std);func.func(stablehlo-legalize-sort);stablehlo-convert-to-signless;canonicalize;scatter-lowering;hlo-custom-call-lowering;cse;func.func(linalg-detensorize{aggressive-mode});detensorize-scf;detensorize-function-boundary;canonicalize;symbol-dce),QuantumCompilationPass(annotate-function;lower-mitigation;lower-gradients;adjoint-lowering),BufferizationPass(inline;convert-tensor-to-linalg;convert-elementwise-to-linalg;gradient-preprocess;one-shot-bufferize{bufferize-function-boundaries         allow-return-allocs-from-loops         function-boundary-type-conversion=identity-layout-map         unknown-type-conversion=identity-layout-map};canonicalize;gradient-postprocess;func.func(buffer-hoisting);func.func(buffer-loop-hoisting);func.func(promote-buffers-to-stack);func.func(buffer-deallocation);convert-arraylist-to-memref;convert-bufferization-to-memref;canonicalize;cp-global-memref),MLIRToLLVMDialect(expand-realloc;convert-gradient-to-llvm;memrefcpy-to-linalgcpy;func.func(convert-linalg-to-loops);convert-scf-to-cf;expand-strided-metadata;lower-affine;arith-expand;convert-complex-to-standard;convert-complex-to-llvm;convert-math-to-llvm;convert-math-to-libm;convert-arith-to-llvm;memref-to-llvm-tbaa;finalize-memref-to-llvm{use-generic-functions};convert-index-to-llvm;convert-catalyst-to-llvm;convert-quantum-to-llvm;emit-catalyst-py-interface;canonicalize;reconcile-unrealized-casts;gep-inbounds;register-inactive-callback)," /tmp/grad.loss_fnbi25h3bs/tmp76lhqb8r.mlir Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH\` to point to it):
0  catalyst  0x000000000afba3eb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  catalyst  0x000000000afb781b llvm::sys::RunSignalHandlers() + 43
2  catalyst  0x000000000afb7941
3  libc.so.6 0x00007fcd5f66c520
4  libc.so.6 0x00007fcd5f6c09fc pthread_kill + 300
5  libc.so.6 0x00007fcd5f66c476 raise + 22
6  libc.so.6 0x00007fcd5f6527f3 abort + 211
7  libc.so.6 0x00007fcd5f65271b
8  libc.so.6 0x00007fcd5f663e96
9  catalyst  0x00000000070be160
10 catalyst  0x00000000070b1f23
11 catalyst  0x000000000ab4f19b mlir::ConversionPattern::matchAndRewrite(mlir::Operation\*, mlir::PatternRewriter&) const + 539
12 catalyst  0x000000000abab5ea mlir::PatternApplicator::matchAndRewrite(mlir::Operation\*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) + 1674
13 catalyst  0x000000000ab515bc
14 catalyst  0x000000000ab51a57 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation\*) + 39
15 catalyst  0x000000000ab5630c mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) + 284
16 catalyst  0x000000000ab58862 mlir::applyPartialConversion(mlir::Operation\*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) + 130
17 catalyst  0x000000000713d0eb
18 catalyst  0x000000000abe4b56 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass\*, mlir::Operation\*, mlir::AnalysisManager, bool, unsigned int) + 1126
19 catalyst  0x000000000abe4f60 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation\*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor\*, mlir::PassInstrumentation::PipelineParentInfo const\*) + 336
20 catalyst  0x000000000abe5e69 mlir::PassManager::run(mlir::Operation\*) + 1193
21 catalyst  0x0000000003fbdffb runPipeline(mlir::PassManager&, catalyst::driver::CompilerOptions const&, catalyst::driver::CompilerOutput&, catalyst::driver::Pipeline&, bool, mlir::ModuleOp) + 251
22 catalyst  0x0000000003fbe84a runLowering(catalyst::driver::CompilerOptions const&, mlir::MLIRContext\*, mlir::ModuleOp, catalyst::driver::CompilerOutput&, mlir::TimingScope&) + 1530
23 catalyst  0x0000000003fc0c55 QuantumDriverMain(catalyst::driver::CompilerOptions const&, catalyst::driver::CompilerOutput&, mlir::DialectRegistry&) + 6645
24 catalyst  0x0000000003fc4a1f QuantumDriverMainFromCL(int, char\*\*) + 9391
25 libc.so.6 0x00007fcd5f653d90
26 libc.so.6 0x00007fcd5f653e40 \__libc_start_main + 128
27 catalyst  0x0000000003fa01ee \_start + 46

Hi @minn-bj ,

I think there might have been some installation issue with one of your packages.

I can see that the error says:

Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH\ to point to it)

I haven’t seen this error before but you could try following this instruction. I think this might resolve your error. Otherwise let me know and we can look deeper into it.

I hope this helps!

Hi @CatalinaAlbornoz, the symbolizer just helps getting more meaningful stack traces when there is a crash, but it’s not required.

I think the key line is this one:

CompileError: catalyst failed with error code -6: catalyst:
/\__w/catalyst/catalyst/mlir/lib/Gradient/Transforms/ConversionPatterns.cpp:225:
virtual llvm::LogicalResult {anonymous}::AdjointOpPattern::matchAndRewrite(catalyst::gradient::AdjointOp, catalyst::gradient::AdjointOpAdaptor, mlir::ConversionPatternRewriter&) const:
Assertion `callee && callee.getNumResults() == 2 && "invalid qfunc symbol in adjoint op"' failed.

This looks like a legitimate bug, we’ll look into it :slight_smile:

Thank you both for your fast reply.
After I updated my environment, some error still appears. Hopefully this can help you @David_Ittah .

best regards

minn-bj

--------------------------------------------------------------------------- CalledProcessError Traceback (most recent call last) File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:448, in Compiler.run_from_ir(self, ir, module_name, workspace) 447 print(f"[SYSTEM] {’ ‘.join(cmd)}", file=self.options.logfile) → 448 result = subprocess.run(cmd, check=True, capture_output=True, text=True) 449 if self.options.verbose or os.getenv(“ENABLE_DIAGNOSTICS”): File /opt/conda/lib/python3.11/subprocess.py:571, in run(input, capture_output, timeout, check, *popenargs, **kwargs) 570 if check and retcode: → 571 raise CalledProcessError(retcode, process.args, 572 output=stdout, stderr=stderr) 573 return CompletedProcess(process.args, retcode, stdout, stderr) CalledProcessError: Command ‘[’/opt/conda/bin/catalyst’, ‘-o’, ‘/tmp/grad.loss_fnwrg87nac/grad.loss_fn.ll’, ‘–module-name’, ‘grad.loss_fn’, ‘–workspace’, ‘/tmp/grad.loss_fnwrg87nac’, ‘-verify-each=false’, ‘–catalyst-pipeline’, ‘EnforceRuntimeInvariantsPass(split-multiple-tapes;builtin.module(apply-transform-sequence);inline-nested-module),HLOLoweringPass(canonicalize;func.func(chlo-legalize-to-stablehlo);func.func(stablehlo-legalize-control-flow);func.func(stablehlo-aggressive-simplification);stablehlo-legalize-to-linalg;func.func(stablehlo-legalize-to-std);func.func(stablehlo-legalize-sort);stablehlo-convert-to-signless;canonicalize;scatter-lowering;hlo-custom-call-lowering;cse;func.func(linalg-detensorize{aggressive-mode});detensorize-scf;detensorize-function-boundary;canonicalize;symbol-dce),QuantumCompilationPass(annotate-function;lower-mitigation;lower-gradients;adjoint-lowering),BufferizationPass(inline;convert-tensor-to-linalg;convert-elementwise-to-linalg;gradient-preprocess;one-shot-bufferize{bufferize-function-boundaries allow-return-allocs-from-loops function-boundary-type-conversion=identity-layout-map unknown-type-conversion=identity-layout-map};canonicalize;gradient-postprocess;func.func(buffer-hoisting);func.func(buffer-loop-hoisting);func.func(promote-buffers-to-stack);func.func(buffer-deallocation);convert-arraylist-to-memref;convert-bufferization-to-memref;canonicalize;cp-global-memref),MLIRToLLVMDialect(expand-realloc;convert-gradient-to-llvm;memrefcpy-to-linalgcpy;func.func(convert-linalg-to-loops);convert-scf-to-cf;expand-strided-metadata;lower-affine;arith-expand;convert-complex-to-standard;convert-complex-to-llvm;convert-math-to-llvm;convert-math-to-libm;convert-arith-to-llvm;memref-to-llvm-tbaa;finalize-memref-to-llvm{use-generic-functions};convert-index-to-llvm;convert-catalyst-to-llvm;convert-quantum-to-llvm;emit-catalyst-py-interface;canonicalize;reconcile-unrealized-casts;gep-inbounds;register-inactive-callback),’, ‘/tmp/grad.loss_fnwrg87nac/tmpzynl6g8_.mlir’]’ died with <Signals.SIGABRT: 6>. The above exception was the direct cause of the following exception: CompileError Traceback (most recent call last) Cell In[2], line 42 39 grad = qml.qjit(catalyst.grad(loss_fn, method=“auto”)) 41 # Compute Grad —> 42 print(grad(weights, data)) File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(*args, **kwargs) 54 s_caller = “::L”.join( 55 [str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]] 56 ) 57 lgr.debug( 58 f"Calling {f_string} from {s_caller}“, 59 **_debug_log_kwargs, 60 ) —> 61 return func(*args, **kwargs) File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:590, in QJIT._call_(self, *args, **kwargs) 586 kwargs = {“static_argnums”: self.compile_options.static_argnums, **kwargs} 588 return self.user_function(*args, **kwargs) → 590 requires_promotion = self.jit_compile(args, **kwargs) 592 # If we receive tracers as input, dispatch to the JAX integration. 593 if any(isinstance(arg, jax.core.Tracer) for arg in tree_flatten(args)[0]): File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(*args, **kwargs) 54 s_caller = “::L”.join( 55 [str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]] 56 ) 57 lgr.debug( 58 f"Calling {f_string} from {s_caller}”, 59 **_debug_log_kwargs, 60 ) —> 61 return func(*args, **kwargs) File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:666, in QJIT.jit_compile(self, args, **kwargs) 663 self.jaxpr, self.out_type, self.out_treedef, self.c_sig = self.capture(args, **kwargs) 665 self.mlir_module = self.generate_ir() → 666 self.compiled_function, _ = self.compile() 668 self.fn_cache.insert(self.compiled_function, args, self.out_treedef, self.workspace) 670 elif self.compiled_function is not cached_fn.compiled_fn: 671 # Restore active state from cache. File /opt/conda/lib/python3.11/site-packages/catalyst/debug/instruments.py:145, in instrument..wrapper(*args, **kwargs) 142 @functools.wrapsfunctools.wraps(fn) 143 def wrapper(*args, **kwargs): 144 if not InstrumentSession.active: → 145 return fn(*args, **kwargs) 147 with ResultReporter(stage_name, has_finegrained) as reporter: 148 self = args[0] File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(*args, **kwargs) 54 s_caller = “::L”.join( 55 [str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]] 56 ) 57 lgr.debug( 58 f"Calling {f_string} from {s_caller}“, 59 **_debug_log_kwargs, 60 ) —> 61 return func(*args, **kwargs) File /opt/conda/lib/python3.11/site-packages/catalyst/jit.py:816, in QJIT.compile(self) 810 shared_object, llvm_ir = self.compiler.run_from_ir( 811 self.overwrite_ir, 812 str(self.mlir_module.operation.attributes[“sym_name”]).replace('”‘, “”), 813 self.workspace, 814 ) 815 else: → 816 shared_object, llvm_ir = self.compiler.run(self.mlir_module, self.workspace) 818 compiled_fn = CompiledFunction( 819 shared_object, func_name, restype, self.out_type, self.compile_options 820 ) 822 return compiled_fn, llvm_ir File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(*args, **kwargs) 54 s_caller = “::L”.join( 55 [str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]] 56 ) 57 lgr.debug( 58 f"Calling {f_string} from {s_caller}", 59 **_debug_log_kwargs, 60 ) —> 61 return func(*args, **kwargs) File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:522, in Compiler.run(self, mlir_module, *args, **kwargs) 519 compiler = PythonCompiler() 520 mlir_module = compiler.run(mlir_module) → 522 return self.run_from_ir( 523 mlir_module.operation.get_asm( 524 binary=False, print_generic_op_form=False, assume_verified=True 525 ), 526 str(mlir_module.operation.attributes[“sym_name”]).replace(’“', “”), 527 *args, 528 **kwargs, 529 ) File /opt/conda/lib/python3.11/site-packages/pennylane/logging/decorators.py:61, in log_string_debug_func..wrapper_entry(*args, **kwargs) 54 s_caller = “::L”.join( 55 [str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]] 56 ) 57 lgr.debug( 58 f"Calling {f_string} from {s_caller}”, 59 **_debug_log_kwargs, 60 ) —> 61 return func(*args, **kwargs) File /opt/conda/lib/python3.11/site-packages/catalyst/compiler.py:455, in Compiler.run_from_ir(self, ir, module_name, workspace) 453 print(result.stderr.strip(), file=self.options.logfile) 454 except subprocess.CalledProcessError as e: # pragma: nocover → 455 raise CompileError(f"catalyst failed with error code {e.returncode}: {e.stderr}") from e 457 if os.path.exists(output_ir_name): 458 with open(output_ir_name, “r”, encoding=“utf-8”) as f: CompileError: catalyst failed with error code -6: catalyst: /__w/catalyst/catalyst/mlir/lib/Gradient/Transforms/ConversionPatterns.cpp:225: virtual llvm::LogicalResult {anonymous}::AdjointOpPattern::matchAndRewrite(catalyst::gradient::AdjointOp, catalyst::gradient::AdjointOpAdaptor, mlir::ConversionPatternRewriter&) const: Assertion `callee && callee.getNumResults() == 2 && “invalid qfunc symbol in adjoint op”’ failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/conda/bin/catalyst -o /tmp/grad.loss_fnwrg87nac/grad.loss_fn.ll --module-name grad.loss_fn --workspace /tmp/grad.loss_fnwrg87nac -verify-each=false --catalyst-pipeline “EnforceRuntimeInvariantsPass(split-multiple-tapes;builtin.module(apply-transform-sequence);inline-nested-module),HLOLoweringPass(canonicalize;func.func(chlo-legalize-to-stablehlo);func.func(stablehlo-legalize-control-flow);func.func(stablehlo-aggressive-simplification);stablehlo-legalize-to-linalg;func.func(stablehlo-legalize-to-std);func.func(stablehlo-legalize-sort);stablehlo-convert-to-signless;canonicalize;scatter-lowering;hlo-custom-call-lowering;cse;func.func(linalg-detensorize{aggressive-mode});detensorize-scf;detensorize-function-boundary;canonicalize;symbol-dce),QuantumCompilationPass(annotate-function;lower-mitigation;lower-gradients;adjoint-lowering),BufferizationPass(inline;convert-tensor-to-linalg;convert-elementwise-to-linalg;gradient-preprocess;one-shot-bufferize{bufferize-function-boundaries allow-return-allocs-from-loops function-boundary-type-conversion=identity-layout-map unknown-type-conversion=identity-layout-map};canonicalize;gradient-postprocess;func.func(buffer-hoisting);func.func(buffer-loop-hoisting);func.func(promote-buffers-to-stack);func.func(buffer-deallocation);convert-arraylist-to-memref;convert-bufferization-to-memref;canonicalize;cp-global-memref),MLIRToLLVMDialect(expand-realloc;convert-gradient-to-llvm;memrefcpy-to-linalgcpy;func.func(convert-linalg-to-loops);convert-scf-to-cf;expand-strided-metadata;lower-affine;arith-expand;convert-complex-to-standard;convert-complex-to-llvm;convert-math-to-llvm;convert-math-to-libm;convert-arith-to-llvm;memref-to-llvm-tbaa;finalize-memref-to-llvm{use-generic-functions};convert-index-to-llvm;convert-catalyst-to-llvm;convert-quantum-to-llvm;emit-catalyst-py-interface;canonicalize;reconcile-unrealized-casts;gep-inbounds;register-inactive-callback),” /tmp/grad.loss_fnwrg87nac/tmpzynl6g8_.mlir #0 0x000000000afba3eb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/conda/bin/catalyst+0xafba3eb) #1 0x000000000afb781b llvm::sys::RunSignalHandlers() (/opt/conda/bin/catalyst+0xafb781b) #2 0x000000000afb7941 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #3 0x00007f62c92cf520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007f62c93239fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007f62c92cf476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007f62c92b57f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007f62c92b571b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007f62c92c6e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x00000000070be160 (anonymous namespace)::AdjointOpPattern::matchAndRewrite(catalyst::gradient::AdjointOp, catalyst::gradient::AdjointOpAdaptor, mlir::ConversionPatternRewriter&) const ConversionPatterns.cpp:0:0 #10 0x00000000070b1f23 mlir::ConvertOpToLLVMPatterncatalyst::gradient::AdjointOp::matchAndRewrite(mlir::Operation*, llvm::ArrayRefmlir::ValueRange, mlir::ConversionPatternRewriter&) const ConversionPatterns.cpp:0:0 #11 0x000000000ab4f19b mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/opt/conda/bin/catalyst+0xab4f19b) #12 0x000000000abab5ea mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/opt/conda/bin/catalyst+0xabab5ea) #13 0x000000000ab515bc (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0 #14 0x000000000ab51a57 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/opt/conda/bin/catalyst+0xab51a57) #15 0x000000000ab5630c mlir::OperationConverter::convertOperations(llvm::ArrayRefmlir::Operation\*) (/opt/conda/bin/catalyst+0xab5630c) #16 0x000000000ab58862 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/opt/conda/bin/catalyst+0xab58862) #17 0x000000000713d0eb catalyst::gradient::GradientConversionPass::runOnOperation() gradient_to_llvm.cpp:0:0 #18 0x000000000abe4b56 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/opt/conda/bin/catalyst+0xabe4b56) #19 0x000000000abe4f60 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/opt/conda/bin/catalyst+0xabe4f60) #20 0x000000000abe5e69 mlir::PassManager::run(mlir::Operation*) (/opt/conda/bin/catalyst+0xabe5e69) #21 0x0000000003fbdffb runPipeline(mlir::PassManager&, catalyst::driver::CompilerOptions const&, catalyst::driver::CompilerOutput&, catalyst::driver::Pipeline&, bool, mlir::ModuleOp) (/opt/conda/bin/catalyst+0x3fbdffb) #22 0x0000000003fbe84a runLowering(catalyst::driver::CompilerOptions const&, mlir::MLIRContext*, mlir::ModuleOp, catalyst::driver::CompilerOutput&, mlir::TimingScope&) (/opt/conda/bin/catalyst+0x3fbe84a) #23 0x0000000003fc0c55 QuantumDriverMain(catalyst::driver::CompilerOptions const&, catalyst::driver::CompilerOutput&, mlir::DialectRegistry&) (/opt/conda/bin/catalyst+0x3fc0c55) #24 0x0000000003fc4a1f QuantumDriverMainFromCL(int, char**) (/opt/conda/bin/catalyst+0x3fc4a1f) #25 0x00007f62c92b6d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #26 0x00007f62c92b6e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #27 0x0000000003fa01ee _start (/opt/conda/bin/catalyst+0x3fa01ee)
1 Like

Hi @minn-bj, I apologize I just realized that the issue is returning multiple results from a QNode is not supported with the Adjoint differentiation method in Catalyst. We should definitely raise a better error message for this though!

Instead, you could try using only one return value in your QNode, or using the "parameter-shift” diff method instead of adjoint. Hope this helps!

Cheers