diff --git a/tests/data/ghz.json b/tests/data/ghz.json new file mode 100644 index 0000000..d247ddd --- /dev/null +++ b/tests/data/ghz.json @@ -0,0 +1,14 @@ +{ + "gates": ["H", "CX"], + "testcases": { + "1": { + "output": "0.70710677,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.70710677" + }, + "2": { + "output": "0.70710677, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.70710677" + }, + "3": { + "output": "0.70710677,0,0,0,0,0,0,0.70710677" + } + } +} \ No newline at end of file diff --git a/tests/test_search.py b/tests/test_search.py new file mode 100644 index 0000000..6470c14 --- /dev/null +++ b/tests/test_search.py @@ -0,0 +1,47 @@ +from pathlib import Path + +from qupsy.language import CX, ForCmd, GateCmd, H, Integer, Pgm, SeqCmd, Var +from qupsy.search import search +from qupsy.spec import parse_spec + +DATA_DIR = Path(__file__).parent / "data" + + +def test_search_ghz_last_step(): + init_pgm = Pgm( + "n", + SeqCmd( + GateCmd(H(Integer(0))), + ForCmd("i0", Integer(1), Var("n"), GateCmd(CX(Integer(0)))), + ), + ) + final_pgm = Pgm( + "n", + SeqCmd( + GateCmd(H(Integer(0))), + ForCmd("i0", Integer(1), Var("n"), GateCmd(CX(Integer(0), Var("i0")))), + ), + ) + spec = parse_spec(DATA_DIR / "ghz.json") + synthesized_pgm = search(spec, initial_pgm=init_pgm) + assert synthesized_pgm == final_pgm + + +def test_search_ghz_second_last_step(): + init_pgm = Pgm( + "n", + SeqCmd( + GateCmd(H(Integer(0))), + ForCmd("i0", Integer(1), Var("n"), GateCmd(CX())), + ), + ) + final_pgm = Pgm( + "n", + SeqCmd( + GateCmd(H(Integer(0))), + ForCmd("i0", Integer(1), Var("n"), GateCmd(CX(Integer(0), Var("i0")))), + ), + ) + spec = parse_spec(DATA_DIR / "ghz.json") + synthesized_pgm = search(spec, initial_pgm=init_pgm) + assert synthesized_pgm == final_pgm