Skip to content

Commit 8c6b366

Browse files
committed
Address some feedback
Signed-off-by: Adam Geller <adgeller@nvidia.com>
1 parent e7fc24c commit 8c6b366

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

python/tests/backends/test_pipeline_logging.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
@pytest.fixture(autouse=True)
1717
def reset_target():
18-
cudaq.reset_target()
1918
yield
2019
cudaq.reset_target()
2120

@@ -52,10 +51,13 @@ def observe_kernel():
5251
h(qubit)
5352

5453

54+
PIPELINE_FILE = "pipeline.jsonl"
55+
56+
5557
@pytest.mark.parametrize("target,target_kwargs,supports_run", TARGET_CONFIGS)
5658
def test_pipeline_logging_decorator(tmp_path, monkeypatch, target,
5759
target_kwargs, supports_run):
58-
log_path = tmp_path / "pipeline.jsonl"
60+
log_path = tmp_path / PIPELINE_FILE
5961
monkeypatch.setenv("CUDAQ_PIPELINE_LOG", str(log_path))
6062

6163
if not cudaq.has_target(target):
@@ -82,7 +84,7 @@ def test_pipeline_logging_decorator(tmp_path, monkeypatch, target,
8284

8385

8486
def test_pipeline_logging_builder_default(tmp_path, monkeypatch):
85-
log_path = tmp_path / "pipeline.jsonl"
87+
log_path = tmp_path / PIPELINE_FILE
8688
monkeypatch.setenv("CUDAQ_PIPELINE_LOG", str(log_path))
8789

8890
kernel = cudaq.make_kernel()

runtime/common/BaseRestRemoteClient.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ class BaseRemoteRestRuntimeClient : public RemoteRuntimeClient {
206206
moduleOp.getContext()->disableMultithreading();
207207
pm.enableIRPrinting();
208208
}
209-
cudaq_internal::maybeLogPassPipeline(pm,
210-
name + ":" + passName + "-synth");
209+
210+
cudaq_internal::maybeLogPassPipeline(
211+
pm, cudaq_internal::buildLabel(name, passName + "-synth"));
211212
if (failed(pm.run(moduleOp)))
212213
throw std::runtime_error("Could not successfully apply " + passName +
213214
" synth.");
@@ -250,7 +251,8 @@ class BaseRemoteRestRuntimeClient : public RemoteRuntimeClient {
250251
tm.setEnabled(cudaq::isTimingTagEnabled(cudaq::TIMING_JIT_PASSES));
251252
auto timingScope = tm.getRootScope(); // starts the timer
252253
pm.enableTiming(timingScope); // do this right before pm.run
253-
cudaq_internal::maybeLogPassPipeline(pm, name + ":client");
254+
cudaq_internal::maybeLogPassPipeline(
255+
pm, cudaq_internal::buildLabel(name, "client"));
254256
if (failed(pm.run(moduleOp)))
255257
throw std::runtime_error(
256258
"Remote rest platform: applying IR passes failed.");
@@ -304,7 +306,8 @@ class BaseRemoteRestRuntimeClient : public RemoteRuntimeClient {
304306
mlir::PassManager pm(ctx);
305307
// For now, the server side expects full-QIR.
306308
opt::addAOTPipelineConvertToQIR(pm);
307-
cudaq_internal::maybeLogPassPipeline(pm, name + ":aot-qir");
309+
cudaq_internal::maybeLogPassPipeline(
310+
pm, cudaq_internal::buildLabel(name, "aot-qir"));
308311

309312
if (failed(pm.run(moduleOp)))
310313
throw std::runtime_error(

runtime/common/Compiler.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ std::vector<cudaq::KernelExecution> Compiler::lowerQuakeCodePart2(
313313
moduleOp.getContext()->disableMultithreading();
314314
if (enablePrintMLIREachPass)
315315
pm.enableIRPrinting();
316-
cudaq_internal::maybeLogPassPipeline(pm, kernelName + ":quake-synth");
316+
cudaq_internal::maybeLogPassPipeline(
317+
pm, cudaq_internal::buildLabel(kernelName, "quake-synth"));
317318
if (failed(pm.run(moduleOp)))
318319
throw std::runtime_error("Could not successfully apply quake-synth.");
319320
}
@@ -373,8 +374,9 @@ std::vector<cudaq::KernelExecution> Compiler::lowerQuakeCodePart2(
373374
pm.addPass(mlir::createCanonicalizerPass());
374375
if (enablePrintMLIREachPass)
375376
pm.enableIRPrinting();
376-
cudaq_internal::maybeLogPassPipeline(pm, kernelName +
377-
":resource-count-preprocess");
377+
cudaq_internal::maybeLogPassPipeline(
378+
pm,
379+
cudaq_internal::buildLabel(kernelName, "resource-count-preprocess"));
378380
if (failed(pm.run(moduleOp)))
379381
throw std::runtime_error(
380382
"Could not successfully apply resource count preprocess.");
@@ -456,7 +458,8 @@ std::vector<cudaq::KernelExecution> Compiler::lowerQuakeCodePart2(
456458
tmpModuleOp.getContext()->disableMultithreading();
457459
if (enablePrintMLIREachPass)
458460
pm.enableIRPrinting();
459-
cudaq_internal::maybeLogPassPipeline(pm, kernelName + ":observe-ansatz");
461+
cudaq_internal::maybeLogPassPipeline(
462+
pm, cudaq_internal::buildLabel(kernelName, "observe-ansatz"));
460463
if (failed(pm.run(tmpModuleOp)))
461464
throw std::runtime_error("Could not apply measurements to ansatz.");
462465
// The full pass pipeline was run above, but the ansatz pass can

runtime/common/PassPipelineLogging.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ std::string getPipelineLogPath();
2727
/// This is the results of actually executing the passes
2828
void maybeLogPassPipeline(mlir::PassManager &pm, llvm::StringRef label = {});
2929

30+
std::string buildLabel(const std::string &pipeline_name,
31+
const std::string &specifics) {
32+
return pipeline_name + ":" + specifics;
33+
}
34+
3035
} // namespace cudaq_internal

runtime/cudaq/platform/default/python/QPU.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ specializeKernel(const std::string &name, ModuleOp module,
9595
module.getContext()->disableMultithreading();
9696
pm.enableIRPrinting();
9797
}
98-
cudaq_internal::maybeLogPassPipeline(pm, name + ":python-specialize");
98+
cudaq_internal::maybeLogPassPipeline(
99+
pm, cudaq_internal::buildLabel(name, "python-specialize"));
99100
if (failed(pm.run(module)))
100101
throw std::runtime_error("Could not successfully apply argument synth.");
101102
}
@@ -115,7 +116,8 @@ std::string cudaq::detail::lower_to_qir_llvm(const std::string &name,
115116
cudaq::opt::addAggressiveInlining(pm);
116117
cudaq::opt::createTargetFinalizePipeline(pm);
117118
cudaq::opt::addAOTPipelineConvertToQIR(pm, format);
118-
cudaq_internal::maybeLogPassPipeline(pm, name + ":python-qir");
119+
cudaq_internal::maybeLogPassPipeline(
120+
pm, cudaq_internal::buildLabel(name, "python-qir"));
119121
if (failed(pm.run(module)))
120122
throw std::runtime_error("Conversion to " + format + " failed.");
121123
if (failed(cudaq::verifier::checkQIRLLVMIRDialect(module, format)))
@@ -154,7 +156,8 @@ std::string cudaq::detail::lower_to_openqasm(const std::string &name,
154156
ctx->disableMultithreading();
155157
pm.enableIRPrinting();
156158
}
157-
cudaq_internal::maybeLogPassPipeline(pm, name + ":python-openqasm");
159+
cudaq_internal::maybeLogPassPipeline(
160+
pm, cudaq_internal::buildLabel(name, "python-openqasm"));
158161
if (failed(pm.run(module)))
159162
throw std::runtime_error("Conversion to OpenQASM failed.");
160163
std::string result;

0 commit comments

Comments
 (0)