Skip to content

Commit 32cddbe

Browse files
authored
docs: Add README sample code (#34)
* fix: Correct link directive * fix: Use a raw loop Rob Pike would be proud * fix: Correct flag usage * docs: Add README sample code
1 parent 02d88cf commit 32cddbe

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
"medium" level bindings to qulacs cppsim using cxxbridge.
44

5+
## Usage
6+
7+
This library requires that QULACAS_PATH is set and points at the direction of a qulacs install.
8+
9+
Additionally you will need to include a `build.rs` in your project that provides the -fopenmp
10+
flag to your linker.
11+
12+
```rust
13+
fn main() {
14+
println!("cargo:rustc-link-arg=-fopenmp");
15+
}
16+
```
17+
18+
## Sample Code
19+
20+
```rust
21+
let state = new_quantum_state(3, false);
22+
set_haar_random_state(&state);
23+
// Not a random state here.
24+
25+
let circuit = new_quantum_circuit(3);
26+
add_x_gate(&circuit, 0);
27+
let merged_gate = merge(&new_cnot_gate(0, 1), &new_y_gate(1));
28+
add_gate_copy(&circuit, &merged_gate);
29+
add_r_x_gate(&circuit, 1, 0.5);
30+
update_quantum_state(&circuit, &state, 1);
31+
32+
let observable = new_observable(3);
33+
add_operator(&observable, 2.0.into(), "X 2 Y 1 Z 0");
34+
add_operator(&observable, (-3.0).into(), "Z 2");
35+
let value = get_expectation_value(&observable, &state);
36+
```
37+
538
## Development
639

740
The recommended way to develop is using [devenv.sh](https://devenv.sh/) and [direnv](https://direnv.net/).

devenv.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{ pkgs, lib, config, inputs, ... }:
22
let
3-
qulacs = pkgs.callPackage ./nix/qulacs.nix {};
4-
in {
3+
qulacs = pkgs.callPackage ./nix/qulacs.nix { };
4+
in
5+
{
56
env = {
67
QULACS_PATH = qulacs;
78
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
89
};
9-
10+
1011
packages = [
1112
pkgs.boost
1213
pkgs.eigen
1314
pkgs.mpi
1415
qulacs
15-
16+
1617
pkgs.release-plz
1718
pkgs.cargo-semver-checks
1819
];

0 commit comments

Comments
 (0)