-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
b87045f
commit 85c3281
Showing
1 changed file
with
38 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy as np | ||
|
||
from qupsy.language import CX, H | ||
from qupsy.spec import SpecData, make_spec | ||
|
||
|
||
def test_parse_spec_from_json_data(): | ||
raw_spec: SpecData = { | ||
"gates": ["H", "CX"], | ||
"testcases": { | ||
"1": { | ||
"input": None, | ||
"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": { | ||
"input": None, | ||
"output": "0.70710677, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.70710677", | ||
}, | ||
"3": {"input": None, "output": "0.70710677,0,0,0,0,0,0,0.70710677"}, | ||
}, | ||
} | ||
spec = make_spec(raw_spec) | ||
assert spec.gates == [H, CX] | ||
assert len(spec.testcases) == 3 | ||
for input, output in spec.testcases: | ||
assert isinstance(input, np.ndarray) | ||
assert isinstance(output, np.ndarray) | ||
input_size: int = np.log2(input.size) | ||
output_size: int = np.log2(output.size) | ||
assert input_size == output_size | ||
input_equal_to_one: int = 0 | ||
for i in input: | ||
input_equal_to_one += np.abs(i) ** 2 | ||
assert np.isclose(input_equal_to_one, 1) | ||
output_equal_to_one = 0 | ||
for i in output: | ||
output_equal_to_one += np.abs(i) ** 2 | ||
assert np.isclose(output_equal_to_one, 1) |