MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / setTarget

Method setTarget

python/utils/LinkedLibraryHolder.cpp:424–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422}
423
424void LinkedLibraryHolder::setTarget(
425 const std::string &targetName,
426 std::map<std::string, std::string> extraConfig) {
427 // Do not set the default target if the disallow
428 // flag has been set.
429 if (!cudaq::detail::canModifyTarget())
430 return;
431
432 auto iter = targets.find(targetName);
433 if (iter == targets.end())
434 throw std::runtime_error("Invalid target name (" + targetName + ").");
435
436 auto &target = iter->second;
437 if (!target.config.WarningMsg.empty()) {
438 fmt::print(fmt::fg(fmt::color::red), "[warning] ");
439 // Output the warning message if any
440 fmt::print(fmt::fg(fmt::color::blue), "Target {}: {}\n", target.name,
441 target.config.WarningMsg);
442 }
443 const std::string targetConfigStr =
444 cudaq::config::processRuntimeArgs(target.config, extraConfig);
445 parseRuntimeTarget(cudaqLibPath, target, targetConfigStr);
446
447 CUDAQ_INFO("Setting target={} (sim={}, platform={})", targetName,
448 target.simulatorName, target.platformName);
449 std::string simName = target.simulatorName;
450 if (simName.empty()) {
451 // This target doesn't have a simulator defined, e.g., hardware targets.
452 // We still need a simulator in case of local emulation.
453 // Ensure defaultTarget is fully resolved (it may still be the initial
454 // "qpp-cpu" if deferred initialization hasn't run yet).
455 defaultTarget = resolveDefaultTarget();
456 auto &defaultTargetInfo = targets[defaultTarget];
457 simName = defaultTargetInfo.simulatorName;
458
459 // The precision should match the underlying local simulator that we
460 // selected.
461 target.precision = defaultTargetInfo.precision;
462
463 // This is really a user error: e.g., using `CUDAQ_DEFAULT_SIMULATOR`
464 // environment variable (meant for simulator) to change the default target
465 // to some other targets that are not a simulator.
466 if (simName.empty())
467 throw std::runtime_error("Default target " + defaultTarget +
468 " doesn't define a simulator. Please check your "
469 "CUDAQ_DEFAULT_SIMULATOR environment variable.");
470 }
471 __nvqir__setCircuitSimulator(getSimulator(simName));
472 auto *platform = getPlatform(target.platformName);
473
474 // Provide the already-parsed target config so that
475 // DefaultQuantumPlatform::setTargetBackend can skip re-reading the YAML.
476 platform->runtimeTarget = std::make_unique<cudaq::RuntimeTarget>(target);
477
478 // Pack the config into the backend string name
479 std::string backendConfigStr = targetName;
480 auto potentialServerHelperPath =
481 cudaqLibPath /

Callers 1

NB_MODULEFunction · 0.80

Calls 15

canModifyTargetFunction · 0.85
parseRuntimeTargetFunction · 0.85
getPlatformFunction · 0.85
formatFunction · 0.85
set_communicatorFunction · 0.85
printFunction · 0.50
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected