Skip to content

Commit 07ffe5b

Browse files
mehrdad2mjoeycartererick-xanadudime10
authored
Small improvements in catalyst cli docs, option help, and intermediate file naming (#1405)
**Context:** This PR fixes some small bugs or lack of documentation for catalyst-cli gathered from @dime10's feedbacks. - The `--help` flag seems to dump a lot of unrelated options which makes it difficult to navigate through catalyst options. - The possible stages for the --checkpoint-stage option are not mentioned in the documentation - When using `--checkpoint-stage`, `--save-ir-after-each=pipeline` no longer works. - The output from --save-ir-after-each=pass produces one output for each function when dealing with a function pass which results in a large number of outputs and one has to find the function of interest randomly. **Description of the Change:** - `--help` option now prints all the catalyst-cli specific options first before jumping into mlir-opt options - Added more details to documentation - Fixed the bug for `save-ir-after-each` and `save-ir-after-each` coexisting together. - Output from `save-ir-after-each` now appends the name of the function to the file name making it easier to identify the desired output. **Benefits:** easier experience for catalyst-cli user **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Joey Carter <joseph.carter@xanadu.ai> Co-authored-by: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Co-authored-by: David Ittah <dime10@users.noreply.github.com>
1 parent b29046b commit 07ffe5b

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed

doc/catalyst-cli/catalyst-cli.rst

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ each stage individually. For example:
3232
3333
.. note::
3434

35-
The Catalyst CLI tool is currently only available when Catalyst is built from source, and is not
36-
included when installing Catalyst via pip or from wheels.
35+
If Catalyst is built from source, the ``catalyst-cli`` executable will be located in
36+
the ``mlir/build/bin/`` directory relative to the root of your Catalyst source directory.
3737

38-
After building Catalyst, the ``catalyst-cli`` executable will be available in the
39-
``mlir/build/bin/`` directory.
38+
If Catalyst is installed via pip or from wheels, the executable will be located
39+
in the ``catalyst/bin/`` directory relative to the environment’s installation directory.
4040

4141
Usage
4242
-----
@@ -98,6 +98,23 @@ intermediate files are saved.
9898
Keep intermediate files after each pipeline in the compilation. By default, no intermediate files
9999
are saved. Using ``--keep-intermediate`` is equivalent to using ``--save-ir-after-each=pipeline``.
100100

101+
``--{passname}``
102+
"""""""""""""""
103+
104+
Enable a specific pass. For example, to enable the ``remove-chained-self-inverse`` pass, use
105+
``--remove-chained-self-inverse``.
106+
107+
Catalyst's main ``mlir`` stage is split up into a sequence of pass pipelines that can also be run
108+
individually via this option. In that case, the name of the pipeline is substituted for the pass
109+
name. Currently, the following pipelines are available:
110+
``enforce-runtime-invariants-pipeline``,
111+
``hlo_lowering-pipeline``,
112+
``quantum-compilation-pipeline``,
113+
``bufferization-pipeline``,
114+
``llvm-dialect-lowring-pipeline``, and finally
115+
``default-catalyst-pipeline`` which encompasses all the above as the default pipeline used by the
116+
Catalyst CLI tool if no pass option is specified.
117+
101118
``--catalyst-pipeline=<pipeline1(pass1[;pass2[;...]])[,pipeline2(...)]>``
102119
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
103120

@@ -113,7 +130,7 @@ applies the pass ``inline-nested-module``, we would specify this pipeline config
113130

114131
.. code-block::
115132
116-
--catalyst-pipeline=pipe1(split-multiple-tapes;apply-transform-sequence),pipe2(inline-nested-module)
133+
--catalyst-pipeline="pipe1(split-multiple-tapes;apply-transform-sequence),pipe2(inline-nested-module)"
117134
118135
``--workspace=<path>``
119136
""""""""""""""""""""""
@@ -138,7 +155,14 @@ Enable asynchronous QNodes.
138155
"""""""""""""""""""""""""""""""""""
139156

140157
Define a *checkpoint stage*, used to indicate that the compiler should start only after reaching the
141-
given pass.
158+
given stage. The stages that are currently available are:
159+
160+
* MLIR: ``mlir`` (start with first MLIR stage), ``{pipeline}`` such as any of the built-in pipeline
161+
names described under the ``--{passname}`` option, OR any custom pipeline names if the
162+
``--catalyst-pipeline={pipeline(...),...}`` option is used.
163+
* LLVM: ``llvm_ir`` (start with first LLVM stage), ``CoroOpt``, ``O2Opt``, ``Enzyme``.
164+
Note that ``CoroOpt`` (Coroutine lowering), ``O2Opt`` (O2 optimization), and ``Enzyme``
165+
(automatic differentiation) passes are only run conditionally as needed.
142166

143167
``--dump-catalyst-pipeline[=<true|false>]``
144168
"""""""""""""""""""""""""""""""""""""""""""

doc/releases/changelog-0.10.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
array arguments of the function, in particular when non-64bit datatypes are used.
168168
[(#1338)](https://github.com/PennyLaneAI/catalyst/pull/1338)
169169

170+
* Fixed a bug in catalyst cli where using `checkpoint-stage` would cause `save-ir-after-each`
171+
to not work properly.
172+
[(#1405)](https://github.com/PennyLaneAI/catalyst/pull/1405)
173+
170174
<h3>Internal changes ⚙️</h3>
171175

172176
* Catalyst no longer depends on or pins the `scipy` package. Instead, OpenBLAS is sourced directly
@@ -272,6 +276,10 @@
272276
for transformation passes.
273277
[(#1368)](https://github.com/PennyLaneAI/catalyst/pull/1368)
274278

279+
* Added more details to catalyst-cli documentation specifiying available options for
280+
checkpoint-stage and default pipelines
281+
[(#1405)](https://github.com/PennyLaneAI/catalyst/pull/1405)
282+
275283
<h3>Contributors ✍️</h3>
276284

277285
This release contains contributions from (in alphabetical order):

mlir/lib/Driver/CompilerDriver.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ LogicalResult preparePassManager(PassManager &pm, const CompilerOptions &options
490490
std::string tmp;
491491
llvm::raw_string_ostream s{tmp};
492492
s << *op;
493-
dumpToFile(options, output.nextPipelineDumpFilename(pipelineName.str()), tmp);
493+
std::string fileName = pipelineName.str();
494+
if (auto funcOp = dyn_cast<mlir::func::FuncOp>(op)) {
495+
fileName += "_" + funcOp.getName().str();
496+
}
497+
dumpToFile(options, output.nextPipelineDumpFilename(fileName), tmp);
494498
}
495499
};
496500

@@ -551,7 +555,7 @@ LogicalResult runPipeline(PassManager &pm, const CompilerOptions &options, Compi
551555
llvm::errs() << "Failed to run pipeline: " << pipeline.getName() << "\n";
552556
return failure();
553557
}
554-
if (options.keepIntermediate && options.checkpointStage.empty()) {
558+
if (options.keepIntermediate && (options.checkpointStage.empty() || output.isCheckpointFound)) {
555559
std::string tmp;
556560
llvm::raw_string_ostream s{tmp};
557561
s << moduleOp;
@@ -564,7 +568,7 @@ LogicalResult runLowering(const CompilerOptions &options, MLIRContext *ctx, Modu
564568
CompilerOutput &output, TimingScope &timing)
565569

566570
{
567-
if (options.keepIntermediate && options.checkpointStage.empty()) {
571+
if (options.keepIntermediate && (options.checkpointStage.empty() || output.isCheckpointFound)) {
568572
std::string tmp;
569573
llvm::raw_string_ostream s{tmp};
570574
s << moduleOp;
@@ -861,26 +865,30 @@ int QuantumDriverMainFromCL(int argc, char **argv)
861865
// ---------
862866
// Any modifications made to the command-line interface should be documented in
863867
// doc/catalyst-cli/catalyst-cli.rst
864-
cl::opt<std::string> WorkspaceDir("workspace", cl::desc("Workspace directory"), cl::init("."));
868+
cl::OptionCategory CatalystCat("Catalyst-cli Options", "");
869+
cl::opt<std::string> WorkspaceDir("workspace", cl::desc("Workspace directory"), cl::init("."),
870+
cl::cat(CatalystCat));
865871
cl::opt<std::string> ModuleName("module-name", cl::desc("Module name"),
866-
cl::init("catalyst_module"));
872+
cl::init("catalyst_module"), cl::cat(CatalystCat));
867873

868874
cl::opt<enum SaveTemps> SaveAfterEach(
869875
"save-ir-after-each", cl::desc("Keep intermediate files after each pass or pipeline"),
870876
cl::values(clEnumValN(SaveTemps::AfterPass, "pass", "Save IR after each pass")),
871877
cl::values(clEnumValN(SaveTemps::AfterPipeline, "pipeline", "Save IR after each pipeline")),
872-
cl::init(SaveTemps::None));
878+
cl::init(SaveTemps::None), cl::cat(CatalystCat));
873879
cl::opt<bool> KeepIntermediate(
874880
"keep-intermediate", cl::desc("Keep intermediate files"), cl::init(false),
875-
cl::callback([&](const bool &) { SaveAfterEach.setValue(SaveTemps::AfterPipeline); }));
881+
cl::callback([&](const bool &) { SaveAfterEach.setValue(SaveTemps::AfterPipeline); }),
882+
cl::cat(CatalystCat));
876883
cl::opt<bool> AsyncQNodes("async-qnodes", cl::desc("Enable asynchronous QNodes"),
877-
cl::init(false));
878-
cl::opt<bool> Verbose("verbose", cl::desc("Set verbose"), cl::init(false));
879-
cl::list<std::string> CatalystPipeline("catalyst-pipeline",
880-
cl::desc("Catalyst Compiler pass pipelines"),
881-
cl::ZeroOrMore, cl::CommaSeparated);
884+
cl::init(false), cl::cat(CatalystCat));
885+
cl::opt<bool> Verbose("verbose", cl::desc("Set verbose"), cl::init(false),
886+
cl::cat(CatalystCat));
887+
cl::list<std::string> CatalystPipeline(
888+
"catalyst-pipeline", cl::desc("Catalyst Compiler pass pipelines"), cl::ZeroOrMore,
889+
cl::CommaSeparated, cl::cat(CatalystCat));
882890
cl::opt<std::string> CheckpointStage("checkpoint-stage", cl::desc("Checkpoint stage"),
883-
cl::init(""));
891+
cl::init(""), cl::cat(CatalystCat));
884892
cl::opt<enum Action> LoweringAction(
885893
"tool", cl::desc("Select the tool to isolate"),
886894
cl::values(clEnumValN(Action::OPT, "opt", "run quantum-opt on the MLIR input")),
@@ -889,9 +897,10 @@ int QuantumDriverMainFromCL(int argc, char **argv)
889897
cl::values(clEnumValN(Action::LLC, "llc", "run llc on the llvm IR input")),
890898
cl::values(clEnumValN(Action::All, "all",
891899
"run quantum-opt, mlir-translate, and llc on the MLIR input")),
892-
cl::init(Action::All));
893-
cl::opt<bool> DumpPassPipeline(
894-
"dump-catalyst-pipeline", cl::desc("Print the pipeline that will be run"), cl::init(false));
900+
cl::init(Action::All), cl::cat(CatalystCat));
901+
cl::opt<bool> DumpPassPipeline("dump-catalyst-pipeline",
902+
cl::desc("Print the pipeline that will be run"), cl::init(false),
903+
cl::cat(CatalystCat));
895904

896905
// Create dialect registry
897906
DialectRegistry registry;
@@ -904,8 +913,13 @@ int QuantumDriverMainFromCL(int argc, char **argv)
904913

905914
// Register and parse command line options.
906915
std::string inputFilename, outputFilename;
916+
std::string helpStr = "Catalyst Command Line Interface options. \n"
917+
"Below, there is a complete list of options for the Catalyst CLI tool"
918+
"In the first section, you can find the options that are used to"
919+
"configure the Catalyst compiler. Next, you can find the options"
920+
"specific to the mlir-opt tool.\n";
907921
std::tie(inputFilename, outputFilename) =
908-
registerAndParseCLIOptions(argc, argv, "quantum compiler", registry);
922+
registerAndParseCLIOptions(argc, argv, helpStr, registry);
909923
llvm::InitLLVM y(argc, argv);
910924
MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();
911925

0 commit comments

Comments
 (0)