Skip to content

Commit edb7e19

Browse files
authored
Add CTest for testing Qiskit C++ (#119)
* Add ctest * igonore test/Testing * igonore test/Testing * fix path to clone Qiskit * Fix boundary data type in obs * add circuit test cases * restore commented line * fix sx test * modify readme
1 parent bdb24ce commit edb7e19

17 files changed

Lines changed: 870 additions & 24 deletions

.github/workflows/tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Qiskit C++ test cases
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
tests:
10+
name: tests-qiskit-cpp-${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os:
16+
- ubuntu-latest
17+
- macos-13
18+
- macos-14
19+
- ubuntu-24.04-arm
20+
- windows-latest
21+
steps:
22+
- uses: actions/checkout@v5
23+
- name: install deps
24+
run: cargo install cbindgen
25+
- name: clone Qiskit
26+
uses: actions/checkout@v5
27+
with:
28+
repository: Qiskit/qiskit
29+
path: test/deps/qiskit
30+
- name: Run tests
31+
run: |
32+
cd test
33+
make

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ coverage.xml
5050
.hypothesis/
5151
.pytest_cache/
5252
cover/
53+
samples/build
54+
test/build
55+
test/deps
56+
test/Testing
5357

5458
# Translations
5559
*.mo

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,27 @@ Qiskit C++ only has C++ header files. There is nothing to do to build the SDK.
7878

7979
### Running examples
8080

81-
Examples are available in [this directory](./tests).
81+
Examples are available in [this directory](./samples).
8282

8383
#### Building examples
8484

8585
To build application using Qiskit C++, add path to Qiskit C-API, include path to `qiskit.h` (installed in `dist/c/include`) and library `libqiskit.so` (installed in `dist/c/lib`) or `qiskit_cext.dll.lib` (generated in `target/release`) for Windows.
86-
See ./CMakeLists.txt for example to make test program.
86+
See ./samples/CMakeLists.txt for example to make test program.
8787

8888
```shell-session
89+
$ cd samples
8990
$ mkdir build
9091
$ cd build
9192
$ cmake -DQISKIT_ROOT=Path_to_qiskit ..
9293
$ make
9394
```
9495

95-
If you want to build sampler/transpiler example, you will need one of qiskit-ibm-runtime C or QRMI.
96+
If you want to build sampler or transpiler example, you will need one of qiskit-ibm-runtime C or QRMI.
9697

9798
Then example can be built by setting `QISKIT_IBM_RUNTIME_C_ROOT` or `QRMI_ROOT` to cmake.
9899

99100
```shell-session
101+
$ cd samples
100102
$ mkdir build
101103
$ cd build
102104
$ cmake -DQISKIT_ROOT=Path_to_qiskit -DQISKIT_IBM_RUNTIME_C_ROOT="path to qiskit-ibm-runtime C" or -DQRMI_ROOT="path to QRMI" ..
@@ -121,13 +123,10 @@ Refer to `./src/providers/qrmi_backend.hpp` and `./src/providers/qrmi_job.hpp` f
121123

122124
Regardless if you are part of the core team or an external contributor, welcome and thank you for contributing to Qiskit C++
123125

124-
### Solving linting/format issues
125-
126-
Contributor must execute the commands below and fix any issues before submitting Pull Request.
127-
128126
### Running unit test
129127

130-
Contributor must execute the command below and fix any issues before submitting Pull Request.
128+
Contributor must add test cases under ./test directory if you have added new features to Qiskit C++.
129+
Also all the test cases running on the github repository should be passed.
131130

132131
### Checking API document
133132

CMakeLists.txt renamed to samples/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function(add_application APP_NAME CPP_FILE)
7676
${QRMI_ROOT}
7777
${QISKIT_IBM_RUNTIME_C_ROOT}/include
7878
${SAMPLES_PATH}
79-
${CMAKE_CURRENT_SOURCE_DIR}/src
79+
${CMAKE_CURRENT_SOURCE_DIR}/../src
8080
nlohmann_json::nlohmann_json
8181
)
8282

@@ -85,14 +85,13 @@ endfunction()
8585

8686
function(add_application_test TEST_NAME APP_NAME CPP_FILE)
8787
add_application(${APP_NAME} ${CPP_FILE})
88-
target_include_directories(${APP_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/external)
8988
add_test(NAME ${TEST_NAME} COMMAND ${APP_NAME})
9089
endfunction()
9190

92-
add_application(circuit_test tests/circuit_test.cpp)
93-
add_application(observable_test tests/observable_test.cpp)
91+
add_application(circuit_test circuit_test.cpp)
92+
add_application(observable_test observable_test.cpp)
9493

9594
if(QRMI_ROOT OR QISKIT_IBM_RUNTIME_C_ROOT)
96-
add_application(sampler_test tests/sampler_test.cpp)
97-
add_application(transpile_test tests/transpile_test.cpp)
95+
add_application(sampler_test sampler_test.cpp)
96+
add_application(transpile_test transpile_test.cpp)
9897
endif()

src/circuit/library/standard_gates/i.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IGate : public Instruction {
2929
public:
3030
IGate(void)
3131
{
32-
name_ = "i";
32+
name_ = "id";
3333
num_qubits_ = 1;
3434
num_clbits_ = 0;
3535
map_ = QkGate_I;

src/circuit/library/standard_gates/standard_gates.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ std::unordered_map<std::string, Instruction> get_standard_gate_name_mapping(void
5757
std::unordered_map<std::string, Instruction> name_mapping;
5858
name_mapping["global_phase"] = GlobalPhaseGate();
5959
name_mapping["h"] = HGate();
60-
name_mapping["i"] = IGate();
60+
name_mapping["id"] = IGate();
6161
name_mapping["x"] = XGate();
6262
name_mapping["y"] = YGate();
6363
name_mapping["z"] = ZGate();
@@ -105,7 +105,7 @@ std::unordered_map<std::string, Instruction> get_standard_gate_name_mapping(void
105105
name_mapping["cswap"] = CSwapGate();
106106
name_mapping["rccx"] = RCCXGate();
107107
name_mapping["mcx"] = MCXGate();
108-
name_mapping["c3sx"] = C3XGate();
108+
name_mapping["c3sx"] = C3SXGate();
109109
name_mapping["rcccx"] = RC3XGate();
110110
return name_mapping;
111111
}

0 commit comments

Comments
 (0)