-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #71 from DVLab-NTU/refactor/tensor-decomp-remove…
…-num-qubit-injection ♻️ remove the need to inject num qubit for tensor decomposer
- Loading branch information
Showing
3 changed files
with
505 additions
and
459 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/**************************************************************************** | ||
PackageName [ tensor ] | ||
Synopsis [ Define tensor decomposer structure ] | ||
Author [ Design Verification Lab ] | ||
Copyright [ Copyright(c) 2023 DVLab, GIEE, NTU, Taiwan ] | ||
****************************************************************************/ | ||
|
||
#include "./decomposer.hpp" | ||
|
||
namespace qsyn::tensor { | ||
|
||
/** | ||
* @brief Append gate and save the encoding gate sequence | ||
* | ||
* @param target | ||
* @param qubit_list | ||
* @param gate_list | ||
*/ | ||
void Decomposer::encode_control_gate(QubitIdList const& target, std::vector<QubitIdList>& qubit_list, std::vector<std::string>& gate_list) { | ||
qubit_list.emplace_back(target); | ||
gate_list.emplace_back(target.size() == 2 ? "cx" : "x"); | ||
_quantum_circuit.add_gate(target.size() == 2 ? "cx" : "x", target, {}, true); | ||
} | ||
|
||
/** | ||
* @brief Gray encoder | ||
* | ||
* @param origin_pos Origin qubit | ||
* @param targ_pos Target qubit | ||
* @param qubit_list | ||
* @param gate_list | ||
*/ | ||
void Decomposer::encode(size_t origin_pos, size_t targ_pos, std::vector<QubitIdList>& qubit_list, std::vector<std::string>& gate_list) { | ||
bool x_given = 0; | ||
if (((origin_pos >> targ_pos) & 1) == 0) { | ||
encode_control_gate({int(targ_pos)}, qubit_list, gate_list); | ||
x_given = 1; | ||
} | ||
for (size_t i = 0; i < _n_qubits; i++) { | ||
if (i == targ_pos) continue; | ||
if (((origin_pos >> i) & 1) == 0) | ||
encode_control_gate({int(targ_pos), int(i)}, qubit_list, gate_list); | ||
} | ||
if (x_given) | ||
encode_control_gate({int(targ_pos)}, qubit_list, gate_list); | ||
} | ||
|
||
} // namespace qsyn::tensor |
Oops, something went wrong.