Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/cpp-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ runs:
- name: Install conan
run: |
pipx install conan
pipx inject conan setuptools
shell: ${{ inputs.shell }}
- name: Get latest CMake
uses: lukka/get-cmake@latest
Expand Down
3 changes: 2 additions & 1 deletion include/libqasm/v3x/instruction_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class InstructionSet {
InstructionListT single_qubit_named_gate_list;
InstructionListT two_qubit_named_gate_list;
InstructionListT non_gate_list;
InstructionListT measure_list;

InstructionSet();

Expand All @@ -34,7 +35,6 @@ class InstructionSet {
std::string single_qubit_gate_composition_prefix = "1q";
std::string two_qubit_gate_composition_prefix = "2q";

std::string measure_name = "measure";
std::string reset_name = "reset";
std::string init_name = "init";
std::string barrier_name = "barrier";
Expand All @@ -53,6 +53,7 @@ class InstructionSet {
[[nodiscard]] const InstructionListT& get_single_qubit_named_gate_list() const;
[[nodiscard]] const InstructionListT& get_two_qubit_named_gate_list() const;
[[nodiscard]] const InstructionListT& get_non_gate_list() const;
[[nodiscard]] const InstructionListT& get_measure_list() const;

[[nodiscard]] bool is_single_qubit_named_gate(const std::string& name) const;
[[nodiscard]] bool is_two_qubit_named_gate(const std::string& name) const;
Expand Down
65 changes: 62 additions & 3 deletions src/v3x/instruction_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,46 @@ InstructionSet::InstructionSet()
{ "CRk", { "i", "QV" } },
{ "CRk", { "i", "VQ" } },
{ "CRk", { "i", "VV" } },
{ "CV", { std::nullopt, "QQ" } },
{ "CV", { std::nullopt, "QV" } },
{ "CV", { std::nullopt, "VQ" } },
{ "CV", { std::nullopt, "VV" } },
{ "CY", { std::nullopt, "QQ" } },
{ "CY", { std::nullopt, "QV" } },
{ "CY", { std::nullopt, "VQ" } },
{ "CY", { std::nullopt, "VV" } },
{ "CZ", { std::nullopt, "QQ" } },
{ "CZ", { std::nullopt, "QV" } },
{ "CZ", { std::nullopt, "VQ" } },
{ "CZ", { std::nullopt, "VV" } },
{ "DCNOT", { std::nullopt, "QQ" } },
{ "DCNOT", { std::nullopt, "QV" } },
{ "DCNOT", { std::nullopt, "VQ" } },
{ "DCNOT", { std::nullopt, "VV" } },
{ "ECR", { std::nullopt, "QQ" } },
{ "ECR", { std::nullopt, "QV" } },
{ "ECR", { std::nullopt, "VQ" } },
{ "ECR", { std::nullopt, "VV" } },
{ "H", { std::nullopt, "Q" } },
{ "H", { std::nullopt, "V" } },
{ "I", { std::nullopt, "Q" } },
{ "I", { std::nullopt, "V" } },
{ "InvSqrtSWAP", { std::nullopt, "QQ" } },
{ "InvSqrtSWAP", { std::nullopt, "QV" } },
{ "InvSqrtSWAP", { std::nullopt, "VQ" } },
{ "InvSqrtSWAP", { std::nullopt, "VV" } },
{ "ISWAP", { std::nullopt, "QQ" } },
{ "ISWAP", { std::nullopt, "QV" } },
{ "ISWAP", { std::nullopt, "VQ" } },
{ "ISWAP", { std::nullopt, "VV" } },
{ "M", { std::nullopt, "QQ" } },
{ "M", { std::nullopt, "QV" } },
{ "M", { std::nullopt, "VQ" } },
{ "M", { std::nullopt, "VV" } },
{ "MS", { std::nullopt, "QQ" } },
{ "MS", { std::nullopt, "QV" } },
{ "MS", { std::nullopt, "VQ" } },
{ "MS", { std::nullopt, "VV" } },
{ "mX90", { std::nullopt, "Q" } },
{ "mX90", { std::nullopt, "V" } },
{ "mY90", { std::nullopt, "Q" } },
Expand All @@ -47,6 +79,14 @@ InstructionSet::InstructionSet()
{ "S", { std::nullopt, "V" } },
{ "Sdag", { std::nullopt, "Q" } },
{ "Sdag", { std::nullopt, "V" } },
{ "SqrtISWAP", { std::nullopt, "QQ" } },
{ "SqrtISWAP", { std::nullopt, "QV" } },
{ "SqrtISWAP", { std::nullopt, "VQ" } },
{ "SqrtISWAP", { std::nullopt, "VV" } },
{ "SqrtSWAP", { std::nullopt, "QQ" } },
{ "SqrtSWAP", { std::nullopt, "QV" } },
{ "SqrtSWAP", { std::nullopt, "VQ" } },
{ "SqrtSWAP", { std::nullopt, "VV" } },
{ "SWAP", { std::nullopt, "QQ" } },
{ "SWAP", { std::nullopt, "QV" } },
{ "SWAP", { std::nullopt, "VQ" } },
Expand Down Expand Up @@ -75,6 +115,18 @@ InstructionSet::InstructionSet()
{ "measure", { std::nullopt, "WV" } },
{ "measure", { std::nullopt, "BV" } },
{ "measure", { std::nullopt, "WQ" } },
{ "measureX", { std::nullopt, "BQ" } },
{ "measureX", { std::nullopt, "WV" } },
{ "measureX", { std::nullopt, "BV" } },
{ "measureX", { std::nullopt, "WQ" } },
{ "measureY", { std::nullopt, "BQ" } },
{ "measureY", { std::nullopt, "WV" } },
{ "measureY", { std::nullopt, "BV" } },
{ "measureY", { std::nullopt, "WQ" } },
{ "measureZ", { std::nullopt, "BQ" } },
{ "measureZ", { std::nullopt, "WV" } },
{ "measureZ", { std::nullopt, "BV" } },
{ "measureZ", { std::nullopt, "WQ" } },
{ "measure", { "fff", "BQ" } },
{ "measure", { "fff", "WV" } },
{ "measure", { "fff", "BV" } },
Expand All @@ -97,10 +149,13 @@ InstructionSet::InstructionSet()
"H", "I", "mX90", "mY90", "mZ90", "Rn", "Rx", "Ry", "Rz", "S", "Sdag", "T", "Tdag", "U", "X", "X90", "Y", "Y90", "Z", "Z90"
}
, two_qubit_named_gate_list{
"CNOT", "CR", "CRk", "CZ", "SWAP"
"CNOT", "CR", "CRk", "CV", "CY", "CZ", "DCNOT", "ECR", "InvSqrtSWAP", "ISWAP", "M", "MS", "SqrtISWAP", "SqrtSWAP", "SWAP"
}
, non_gate_list{
"measure", "reset", "init", "barrier", "wait"
"measure", "measureX", "measureY", "measureZ", "reset", "init", "barrier", "wait"
}
, measure_list{
"measure", "measureX", "measureY", "measureZ"
}
{}
// NOLINTEND
Expand Down Expand Up @@ -134,6 +189,10 @@ InstructionSet::InstructionSet()
return non_gate_list;
}

[[nodiscard]] const InstructionListT& InstructionSet::get_measure_list() const {
return measure_list;
}

[[nodiscard]] bool InstructionSet::is_single_qubit_named_gate(const std::string& name) const {
return single_qubit_named_gate_list.contains(name);
}
Expand Down Expand Up @@ -171,7 +230,7 @@ InstructionSet::InstructionSet()
}

[[nodiscard]] bool InstructionSet::is_measure(const std::string& name) const {
return name == measure_name;
return measure_list.contains(name);
}

[[nodiscard]] bool InstructionSet::is_reset(const std::string& name) const {
Expand Down
12 changes: 9 additions & 3 deletions test/v3x/cpp/test_instruction_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class InstructionSetTest : public ::testing::Test {
const InstructionListT& single_qubit_named_gate_list = instruction_set.get_single_qubit_named_gate_list();
const InstructionListT& two_qubit_named_gate_list = instruction_set.get_two_qubit_named_gate_list();

const size_t number_of_gate_map_entries = 60;
const size_t number_of_non_gate_map_entries = 16;
const size_t number_of_gate_map_entries = 100;
const size_t number_of_non_gate_map_entries = 28;
const size_t number_of_gate_modifier_map_entries = 3;
const size_t number_of_single_qubit_named_gates = 20;
const size_t number_of_two_qubit_named_gates = 5;
const size_t number_of_two_qubit_named_gates = 15;
};

TEST_F(InstructionSetTest, get_instance) {
Expand Down Expand Up @@ -105,7 +105,13 @@ TEST_F(InstructionSetTest, is_gate) {
}
TEST_F(InstructionSetTest, is_measure) {
EXPECT_TRUE(instruction_set.is_measure("measure"));
EXPECT_TRUE(instruction_set.is_measure("measureX"));
EXPECT_TRUE(instruction_set.is_measure("measureY"));
EXPECT_TRUE(instruction_set.is_measure("measureZ"));
EXPECT_FALSE(instruction_set.is_measure("MEASURE"));
EXPECT_FALSE(instruction_set.is_measure("measure_z"));
EXPECT_FALSE(instruction_set.is_measure("MEASUREz"));
EXPECT_FALSE(instruction_set.is_measure("MEASUREZ"));
}
TEST_F(InstructionSetTest, is_reset) {
EXPECT_TRUE(instruction_set.is_reset("reset"));
Expand Down
Loading