Skip to content

Commit d8a1659

Browse files
committed
Remove skipPipelineSubstitution boolean in getCompileTarget
Signed-off-by: Luca Mondada <luca@mondada.net>
1 parent 2b4bf6c commit d8a1659

17 files changed

Lines changed: 84 additions & 67 deletions

File tree

docs/sphinx/using/backends/hardware/backend_iqm.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Emulation Mode
2020
This can be done by setting `mapping_file` to point to a file describing the QPU architecture which should be emulated.
2121
If an architecture is specified no server URL is needed anymore.
2222

23+
Without an architecture file, the target attempts to fetch the dynamic quantum architecture from the server.
24+
If that fetch fails (for example due to missing authentication or no network access), CUDA-Q emits a warning and continues.
25+
Execution modes that do not require qubit mapping, such as detector error model generation, still work in that case.
26+
Execution that does require qubit mapping will fail later with an unresolved architecture placeholder.
27+
2328
.. code:: python
2429
2530
cudaq.set_target('iqm', emulate=True, mapping_file="<path+filename>")
@@ -53,6 +58,11 @@ Emulation Mode
5358
This can be done by specifying a file with the architecture either at compile time or in an variable in the environment executing the binary.
5459
If an architecture is specified no server URL is needed anymore.
5560

61+
Without an architecture file, the target attempts to fetch the dynamic quantum architecture from the server.
62+
If that fetch fails (for example due to missing authentication or no network access), CUDA-Q emits a warning and continues.
63+
Execution modes that do not require qubit mapping, such as detector error model generation, still work in that case.
64+
Execution that does require qubit mapping will fail later with an unresolved architecture placeholder.
65+
5666
.. code:: bash
5767
5868
// With this binary multiple QPU architectures can be tested without recompilation.

python/runtime/cudaq/platform/py_alt_launch_kernel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ static std::pair<cudaq::CompileTarget, cudaq::CompileOptions>
706706
getCompileConfig(std::optional<cudaq::CompileTarget> target = std::nullopt) {
707707
auto *ctx = cudaq::getExecutionContext();
708708
cudaq::CompileOptions options;
709+
if (!target)
710+
target = cudaq::get_compile_target();
709711
if (!ctx) {
710-
if (!target)
711-
target = cudaq::get_compile_target(cudaq::other_policies{});
712712
options = cudaq::get_compile_options(cudaq::other_policies{});
713713
} else {
714714
cudaq::policies::withPolicy(ctx->name, [&](auto policy) {
@@ -717,8 +717,6 @@ getCompileConfig(std::optional<cudaq::CompileTarget> target = std::nullopt) {
717717
policy.spin = ctx->spin.value();
718718
}
719719

720-
if (!target)
721-
target = cudaq::get_compile_target(policy);
722720
options = cudaq::get_compile_options(policy);
723721
});
724722
}

runtime/common/BaseRemoteRESTQPU.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,9 @@ class BaseRemoteRESTQPU : public QPU {
221221
serverHelper, executor);
222222
}
223223

224-
CompileTarget
225-
getCompileTarget(bool skipPipelineSubstitutions = false) override {
226-
std::map<std::string, std::string> pipelineSubstitutions{};
227-
if (!skipPipelineSubstitutions)
228-
pipelineSubstitutions =
229-
serverHelper->getPipelineSubstitutions(platformPath);
224+
CompileTarget getCompileTarget() override {
225+
auto pipelineSubstitutions =
226+
serverHelper->getPipelineSubstitutions(platformPath);
230227
auto target = CompileTarget::createFromConfig(targetConfig, backendConfig,
231228
pipelineSubstitutions);
232229
target.pipelineConfig.replaceStateWithKernel = true;

runtime/cudaq/algorithms/launch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ auto launch(const Policy &policy, std::size_t qpu_id, ExecutionContext &ctx,
8080
cudaq::CompileOptions options;
8181
if constexpr (requires { policy.inner; }) {
8282
options = cudaq::get_compile_options(policy.inner);
83-
target = platform.getCompileTarget(policy.inner, qpu_id);
8483
} else {
8584
options = cudaq::get_compile_options(policy);
86-
target = platform.getCompileTarget(policy, qpu_id);
8785
}
86+
target = platform.getCompileTarget(qpu_id);
8887
const bool isEmulated = platform.is_emulated(qpu_id);
8988
const bool isRemote = platform.is_remote(qpu_id);
9089
options.emulate = isEmulated;

runtime/cudaq/platform.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ inline bool is_simulator_platform() {
4242
return getQuantumPlatformInternal()->is_simulator();
4343
}
4444

45-
template <typename Policy>
46-
cudaq::CompileTarget get_compile_target(const Policy &policy) {
47-
return getQuantumPlatformInternal()->getCompileTarget(policy);
45+
inline cudaq::CompileTarget get_compile_target() {
46+
return getQuantumPlatformInternal()->getCompileTarget();
4847
}
4948

5049
/// Get the default compile target configuration for the given platform

runtime/cudaq/platform/default/DefaultQPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ cudaq::DefaultQPU::launchKernel(const cudaq::ptsbe::sample_policy &policy,
169169
});
170170
}
171171

172-
cudaq::CompileTarget cudaq::DefaultQPU::getCompileTarget(bool) {
172+
cudaq::CompileTarget cudaq::DefaultQPU::getCompileTarget() {
173173
return createDefaultCompileTarget();
174174
}
175175

runtime/cudaq/platform/default/DefaultQPU.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class DefaultQPU : public QPU {
7272
launchKernel(const ptsbe::sample_policy &policy, const CompiledModule &module,
7373
KernelArgs args) override;
7474

75-
CompileTarget
76-
getCompileTarget(bool skipPipelineSubstitutions = false) override;
75+
CompileTarget getCompileTarget() override;
7776

7877
void configureExecutionContext(ExecutionContext &context) const override;
7978
void beginExecution() override;

runtime/cudaq/platform/default/rest/helpers/iqm/IQMServerHelper.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,18 @@ std::map<std::string, std::string> IQMServerHelper::getPipelineSubstitutions(
450450
// Use provided string as path+filename
451451
pathToFile = iter->second;
452452
} else {
453-
// Use the dynamic quantum architecture of the configured IQM server
454-
fetchQuantumArchitecture();
455-
pathToFile = writeQuantumArchitectureFile();
453+
// Use the dynamic quantum architecture of the configured IQM server.
454+
// Fallback to an empty substitution map and let the pipeline report the
455+
// problem if it is ever actually used.
456+
try {
457+
fetchQuantumArchitecture();
458+
pathToFile = writeQuantumArchitectureFile();
459+
} catch (const std::exception &e) {
460+
CUDAQ_WARN("Leaving %QPU_ARCH% unresolved: {}. Set IQM_QPU_QA or pass "
461+
"--mapping-file to supply it offline.",
462+
e.what());
463+
return {};
464+
}
456465
}
457466
}
458467
CUDAQ_INFO("Using quantum architecture file: {}", pathToFile);

runtime/cudaq/platform/fermioniq/FermioniqQPU.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ class FermioniqQPU : public BaseRemoteRESTQPU {
3636
}
3737
}
3838

39-
CompileTarget
40-
getCompileTarget(bool skipPipelineSubstitutions = false) override {
41-
auto target =
42-
BaseRemoteRESTQPU::getCompileTarget(skipPipelineSubstitutions);
39+
CompileTarget getCompileTarget() override {
40+
auto target = BaseRemoteRESTQPU::getCompileTarget();
4341
target.supportObservableMeasurements = true;
4442
return target;
4543
}

runtime/cudaq/platform/orca/OrcaRemoteRESTQPU.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ class OrcaRemoteRESTQPU : public cudaq::QPU {
9292
[[nodiscard]] KernelThunkResultType
9393
launchKernelCommon(const std::string &kernelName, void *args);
9494

95-
CompileTarget
96-
getCompileTarget(bool skipPipelineSubstitutions = false) override {
95+
CompileTarget getCompileTarget() override {
9796
return {
9897
.supportExplicitMeasurements = false,
9998
};

0 commit comments

Comments
 (0)