-
Notifications
You must be signed in to change notification settings - Fork 73
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
4 changed files
with
98 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
SBCL_HOME?=$(HOME)/sbcl | ||
SBCL?=$(SBCL_HOME)/run-sbcl.sh | ||
|
||
.PHONY: all clean | ||
|
||
all: libquilc.dylib | ||
|
||
libquilc.core libquilc.c libquilc.h libquilc.py: src/libquilc.lisp | ||
sbcl --dynamic-space-size 4096 --load "src/build-image.lisp" | ||
$(SBCL) --dynamic-space-size 4096 --load "src/build-image.lisp" | ||
|
||
libquilc.dylib: libquilc.core libquilc.c | ||
gcc -dynamiclib -o $@ libquilc.c -lsbcl | ||
gcc -dynamiclib -o $@ libquilc.c -lsbcl -L$(SBCL_HOME)/src/runtime | ||
|
||
example: example.c libquilc.dylib | ||
gcc src/example.c -o example -lsbcl -lquilc -L. | ||
gcc src/example.c -o example -lsbcl -lquilc -L. -L$(SBCL_HOME)/src/runtime | ||
|
||
clean: | ||
rm -f libquilc.c libquilc.h libquilc.core libquilc.py libquilc.dylib example |
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,55 @@ | ||
from ctypes import * | ||
import json | ||
import sys | ||
|
||
import libquilc | ||
|
||
|
||
def die(msg): | ||
print(msg) | ||
exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
gateset = "PHASE(pi/2) 0, H 0" | ||
sequence = c_char_p() | ||
|
||
if ( | ||
libquilc.quilc_generate_rb_sequence( | ||
2, 1, gateset.encode("utf-8"), 52, None, byref(sequence) | ||
) | ||
!= 0 | ||
): | ||
die("unable to generate RB sequence") | ||
|
||
print(json.loads(sequence.value.decode("utf-8"))) | ||
|
||
indices = "0" | ||
symbols = "X" | ||
clifford = "H 0" | ||
pauli = c_char_p() | ||
|
||
if ( | ||
libquilc.quilc_conjugate_pauli_by_clifford( | ||
indices.encode("utf-8"), | ||
symbols.encode("utf-8"), | ||
clifford.encode("utf-8"), | ||
byref(pauli), | ||
) | ||
!= 0 | ||
): | ||
die("unable to conjugate pauli") | ||
|
||
result = json.loads(pauli.value.decode("utf-8")) | ||
result.pop("_type") | ||
print(result) | ||
|
||
quil = "RX((2+1/2)*pi/7) 0" | ||
raw_result = c_char_p() | ||
|
||
if libquilc.quilc_rewrite_arithmetic(quil.encode("utf-8"), byref(raw_result)) != 0: | ||
die("unable to rewrite arithmetic") | ||
|
||
result = json.loads(raw_result.value.decode("utf-8")) | ||
result.pop("_type") | ||
print(result) |