Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4d59bdd
try z3 with cmake
ritu-thombre99 Jul 3, 2025
bcbb1ba
working z3.h
ritu-thombre99 Jul 3, 2025
fe681c7
cmake resolved with warnings suppressed
ritu-thombre99 Jul 3, 2025
679e44f
revert cmake
ritu-thombre99 Jul 4, 2025
9123bd1
everything except using z3 works
ritu-thombre99 Jul 4, 2025
9f3742f
try external project
ritu-thombre99 Jul 4, 2025
01c71bb
z3 still doesnt work
ritu-thombre99 Jul 4, 2025
41d59b1
z3 fully working
ritu-thombre99 Jul 4, 2025
d0f38db
add TODO for patch
ritu-thombre99 Jul 4, 2025
82df672
got hardware and circuit details
ritu-thombre99 Jul 5, 2025
d4d9ab4
extracting qubits from register
ritu-thombre99 Jul 6, 2025
0cb7b92
fix getOperand to getInQubit
ritu-thombre99 Jul 8, 2025
1073001
add TODO comments
ritu-thombre99 Jul 9, 2025
d888a4f
checking if tqg executable
ritu-thombre99 Jul 10, 2025
a0a4679
compatible with automatic qubit management
ritu-thombre99 Jul 10, 2025
835ae77
demo for ritu
erick-xanadu Jul 22, 2025
bbc3870
proof of concept
erick-xanadu Jul 23, 2025
c15d798
todos
erick-xanadu Jul 23, 2025
a0d770d
proof of concept
erick-xanadu Jul 23, 2025
eb883ad
with f-strings
erick-xanadu Jul 23, 2025
5f6f751
sabre branch
ritu-thombre99 Jul 24, 2025
0c4278c
sabre half done
ritu-thombre99 Jul 24, 2025
8cd7e8d
greedy sabre working
ritu-thombre99 Jul 24, 2025
7817ac1
naive sabre complete
ritu-thombre99 Jul 25, 2025
1e1902e
track with main
ritu-thombre99 Jul 25, 2025
43e3721
change executeGateList type
ritu-thombre99 Jul 25, 2025
e35ccec
track with main
ritu-thombre99 Aug 1, 2025
3562d0b
track with main
ritu-thombre99 Aug 1, 2025
6af5cf8
track with main
ritu-thombre99 Aug 4, 2025
a4756cc
change extractOp logic
ritu-thombre99 Aug 5, 2025
dc65ed5
rename variables
ritu-thombre99 Aug 5, 2025
211784f
add cpmments for erasing original customops
ritu-thombre99 Aug 5, 2025
c7f02fd
fix paths
ritu-thombre99 Aug 5, 2025
4d09a4b
track with main
ritu-thombre99 Aug 5, 2025
36814d3
track with main
ritu-thombre99 Aug 5, 2025
5d83945
runtime specialization
ritu-thombre99 Aug 5, 2025
18e0320
running runtime sepcialization with sabre routing
ritu-thombre99 Aug 5, 2025
07453dc
Delete mlir/lib/Quantum/Transforms/z3.patch
ritu-thombre99 Aug 5, 2025
6d9e8c4
demo for ritu
erick-xanadu Jul 22, 2025
bbcc154
Simplify & improve demo code
dime10 Aug 5, 2025
e74d55a
Add convenient call sig for pure_callback
dime10 Aug 5, 2025
756cd66
Bugfix for incorrect default with static_argnums
dime10 Aug 5, 2025
07d17d5
Implement most todos in the jitting decorator
dime10 Aug 5, 2025
192367b
Better concretization of qnode args
dime10 Aug 5, 2025
04cf295
insert new function
ritu-thombre99 Aug 6, 2025
f65a1f5
new MLIR generated
ritu-thombre99 Aug 8, 2025
696ca97
update hardcode jit example
ritu-thombre99 Aug 8, 2025
4bd8e0d
true_jit commits
ritu-thombre99 Aug 8, 2025
6db11f8
update return state to include latest state
ritu-thombre99 Aug 8, 2025
4a23854
replace original func with newfunc
ritu-thombre99 Aug 8, 2025
d895bc4
replace original func with newfunc
ritu-thombre99 Aug 8, 2025
a3d7e88
fix formatting
ritu-thombre99 Aug 8, 2025
280898c
comment on parametric gates not working
ritu-thombre99 Aug 11, 2025
99a33bf
two sabre passes
ritu-thombre99 Aug 21, 2025
44ee51d
bidirectional SABRE
ritu-thombre99 Aug 21, 2025
c426894
add bfs to get random subgraph
ritu-thombre99 Aug 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frontend/catalyst/api_extensions/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def f(x):
return accelerate_impl(func, dev=dev)


def pure_callback(callback_fn, result_type=None):
def pure_callback(callback_fn=None, *, result_type=None):
"""Execute and return the results of a functionally pure Python
function from within a qjit-compiled function.

Expand Down Expand Up @@ -261,6 +261,11 @@ def vjp(x, dy) -> (jax.ShapeDtypeStruct((2,), jnp.float64),):
>>> f(jnp.array([0.1, 0.2]))
Array([-0.01071923, 0.82698717], dtype=float64)
"""
# Just for convenience
if callback_fn is None:
kwargs = copy.copy(locals())
kwargs.pop("callback_fn")
return functools.partial(pure_callback, **kwargs)

# Verify inputs
if result_type is None:
Expand Down
53 changes: 31 additions & 22 deletions frontend/catalyst/compiled_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,45 @@ def load_symbols(self):
CFuncPtr: handle to the teardown function, which tears down the device
CFuncPtr: handle to the memory transfer function for program results
"""
try:

setup = self.shared_object.setup
setup.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
setup.restypes = ctypes.c_int
setup = self.shared_object.setup
setup.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
setup.restypes = ctypes.c_int

teardown = self.shared_object.teardown
teardown.argtypes = None
teardown.restypes = None
teardown = self.shared_object.teardown
teardown.argtypes = None
teardown.restypes = None

# We are calling the c-interface
function = self.shared_object["_catalyst_pyface_" + self.func_name]
# Guaranteed from _mlir_ciface specification
function.restypes = None
# Not needed, computed from the arguments.
# function.argyptes
except:
setup = None
teardown = None
finally:

mem_transfer = self.shared_object["_mlir_memory_transfer"]
# We are calling the c-interface
function = self.shared_object["_catalyst_pyface_" + self.func_name]
# Guaranteed from _mlir_ciface specification
function.restypes = None
# Not needed, computed from the arguments.
# function.argyptes

return function, setup, teardown, mem_transfer
mem_transfer = self.shared_object["_mlir_memory_transfer"]

return function, setup, teardown, mem_transfer

def __enter__(self):
params_to_setup = [b"jitted-function"]
argc = len(params_to_setup)
array_of_char_ptrs = (ctypes.c_char_p * len(params_to_setup))()
array_of_char_ptrs[:] = params_to_setup
self.setup(ctypes.c_int(argc), array_of_char_ptrs)
if self.setup:
params_to_setup = [b"jitted-function"]
argc = len(params_to_setup)
array_of_char_ptrs = (ctypes.c_char_p * len(params_to_setup))()
array_of_char_ptrs[:] = params_to_setup
self.setup(ctypes.c_int(argc), array_of_char_ptrs)
return self
return self

def __exit__(self, _type, _value, _traceback):
self.teardown()
if self.teardown:
self.teardown()


class CompiledFunction:
Expand Down Expand Up @@ -329,10 +338,10 @@ def get_cmain(self, *args):
return get_template(self.func_name, self.restype, *buffer)

def __call__(self, *args, **kwargs):
static_argnums = self.compile_options.static_argnums
static_argnums = self.compile_options.static_argnums if self.compile_options else ()
dynamic_args = filter_static_args(args, static_argnums)

if self.compile_options.abstracted_axes is not None:
if self.compile_options and self.compile_options.abstracted_axes is not None:
abstracted_axes = self.compile_options.abstracted_axes
dynamic_args = get_implicit_and_explicit_flat_args(
abstracted_axes, *dynamic_args, **kwargs
Expand Down
1 change: 1 addition & 0 deletions mlir/include/Quantum/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ std::unique_ptr<mlir::Pass> createDisentangleCNOTPass();
std::unique_ptr<mlir::Pass> createDisentangleSWAPPass();
std::unique_ptr<mlir::Pass> createIonsDecompositionPass();
std::unique_ptr<mlir::Pass> createLoopBoundaryOptimizationPass();
std::unique_ptr<mlir::Pass> createRoutingPass();

} // namespace catalyst
16 changes: 16 additions & 0 deletions mlir/include/Quantum/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def LoopBoundaryOptimizationPass : Pass<"loop-boundary"> {

let constructor = "catalyst::createLoopBoundaryOptimizationPass()";
}

def RoutingPass : Pass<"route-circuit"> {
let summary = "Perform mapping and routing of quantum circuit to a hardware.";

let constructor = "catalyst::createRoutingPass()";

let options = [
Option<
/*C++ variable name=*/"hardwareGraph",
/*CLI argument=*/"hardware-graph",
/*type=*/"std::string",
/*default=*/"",
/*description=*/"Hardware graph represented by a list of edges connecting physical qubits."
>,
];
}
// ----- Quantum circuit transformation passes end ----- //

#endif // QUANTUM_PASSES
1 change: 1 addition & 0 deletions mlir/lib/Catalyst/Transforms/RegisterAllPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ void catalyst::registerAllCatalystPasses()
mlir::registerPass(catalyst::createScatterLoweringPass);
mlir::registerPass(catalyst::createSplitMultipleTapesPass);
mlir::registerPass(catalyst::createTestPass);
mlir::registerPass(catalyst::createRoutingPass);
}
1 change: 1 addition & 0 deletions mlir/lib/Quantum/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ file(GLOB SRC
IonsDecompositionPatterns.cpp
loop_boundary_optimization.cpp
LoopBoundaryOptimizationPatterns.cpp
route_circuit.cpp
)

get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
Expand Down
Loading
Loading