Download research/certificate.py from PureOne/CNISA-II: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/datasets/PureOne/CNISA-II/resolve/main/research/certificate.py
- Command line
-
hf download hf://datasets/PureOne/CNISA-II/research/certificate.py
-
curl -L -o certificate.py https://huggingface.co/datasets/PureOne/CNISA-II/resolve/main/research/certificate.py
2.43 kB
| """Exact finite-word certificate for collinearity of two switched outputs.""" | |
| from sympy import Matrix, eye, kronecker_product, zeros | |
| def lift(actual, reference): | |
| return (kronecker_product(actual, eye(reference.rows)) + | |
| kronecker_product(eye(actual.rows), reference)) | |
| def wedge_map(actual_readout, reference_readout): | |
| C, D = actual_readout, reference_readout | |
| if C.rows != D.rows or C.rows < 2: | |
| raise ValueError("Use at least two corresponding output channels") | |
| rows = [kronecker_product(C.row(i), D.row(j)) - kronecker_product(C.row(j), D.row(i)) | |
| for i in range(C.rows) for j in range(i+1, C.rows)] | |
| return Matrix.vstack(*rows) | |
| def span(columns): | |
| return Matrix.hstack(*columns).columnspace() | |
| def close_under(basis, letters): | |
| while True: | |
| extended = span(basis + [A*v for A in letters for v in basis]) | |
| if len(extended) == len(basis): | |
| return extended | |
| basis = extended | |
| def protection_order(initial, readout, zero_cost, defects): | |
| """A None order means exact vanishing at all degrees for this alphabet. | |
| Supply exact SymPy matrices and independently switchable defect letters. | |
| The initial vector and wedge readout must already live on the tensor lift. | |
| """ | |
| basis = close_under([initial], zero_cost) | |
| dimensions = [] | |
| while True: | |
| dimensions.append(len(basis)) | |
| if any(readout*v != zeros(readout.rows, 1) for v in basis): | |
| return len(dimensions)-1, dimensions | |
| extended = close_under(span(basis + [E*v for E in defects for v in basis]), zero_cost) | |
| if len(extended) == len(basis): | |
| return None, dimensions | |
| basis = extended | |
| def example(): | |
| C = Matrix([[1,0,0],[0,1,0]]) | |
| D = eye(2) | |
| source = kronecker_product(eye(3).col(0),eye(2).col(0)) | |
| W = wedge_map(C,D) | |
| signal = lift(Matrix([[0,0,0],[1,0,0],[0,0,0]]), Matrix([[0,0],[1,0]])) | |
| go_hidden = lift(eye(3).col(2)*eye(3).row(0),zeros(2)) | |
| come_back = lift(eye(3).col(1)*eye(3).row(2),zeros(2)) | |
| exact = protection_order(source,W,[signal],[go_hidden]) | |
| degree_two = protection_order(source,W,[signal],[go_hidden,come_back]) | |
| assert exact[0] is None and degree_two[0] == 2 | |
| return dict(one_way_order=exact[0], one_way_dimensions=exact[1], | |
| return_order=degree_two[0], return_dimensions=degree_two[1]) | |
| if __name__ == '__main__': | |
| print(example()) | |