-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
114 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ set(COMMON_RUNTIME_SRC | |
NoiseModel.cpp | ||
ServerHelper.cpp | ||
Resources.cpp | ||
Trace.cpp | ||
Future.cpp | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#include "Trace.h" | ||
#include <algorithm> | ||
#include <cassert> | ||
|
||
namespace cudaq { | ||
|
||
void Trace::appendInstruction(std::string_view name, std::vector<double> params, | ||
std::vector<std::size_t> controls, | ||
std::vector<std::size_t> targets) { | ||
assert(!targets.empty() && "A instruction must have at least one target"); | ||
std::size_t maxID = *std::max_element(targets.begin(), targets.end()); | ||
if (!controls.empty()) | ||
maxID = | ||
std::max(maxID, *std::max_element(controls.begin(), controls.end())); | ||
numQudits = std::max(numQudits, maxID + 1); | ||
instructions.emplace_back(name, params, controls, targets); | ||
} | ||
|
||
} // namespace cudaq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/****************************************************************-*- C++ -*-**** | ||
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace cudaq { | ||
|
||
/// @brief A trace is a circuit representation of the executed computation, as | ||
/// seen by the execution manager. (Here, a circuit is represented as a list | ||
/// of instructions on qudits). Since the execution manager cannot "see" control | ||
/// flow, the trace of a kernel with control flow represents a single execution | ||
/// path, and thus two calls to the same kernel might produce traces. | ||
class Trace { | ||
public: | ||
struct Instruction { | ||
std::string name; | ||
std::vector<double> params; | ||
std::vector<std::size_t> controls; | ||
std::vector<std::size_t> targets; | ||
|
||
Instruction(std::string_view name, std::vector<double> params, | ||
std::vector<std::size_t> controls, | ||
std::vector<std::size_t> targets) | ||
: name(name), params(params), controls(controls), targets(targets) {} | ||
}; | ||
|
||
void appendInstruction(std::string_view name, std::vector<double> params, | ||
std::vector<std::size_t> controls, | ||
std::vector<std::size_t> targets); | ||
|
||
auto getNumQudits() const { return numQudits; } | ||
|
||
auto begin() const { return instructions.begin(); } | ||
|
||
auto end() const { return instructions.end(); } | ||
|
||
private: | ||
std::size_t numQudits = 0; | ||
std::vector<Instruction> instructions; | ||
}; | ||
|
||
} // namespace cudaq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters