Skip to content

Commit 4fb5572

Browse files
committed
add example matrix generator
1 parent ed72906 commit 4fb5572

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

app/generate.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
from scipy.stats import unitary_group
3+
4+
5+
def generate_random_unitary(n):
6+
"""Generate a random n x n unitary matrix."""
7+
return unitary_group.rvs(n, random_state=42)
8+
9+
10+
def generate_multiplicity_vectors(n, max_val=5):
11+
"""Generate row and column multiplicity vectors with random values from 0 to max_val,
12+
ensuring their sums are equal."""
13+
rng = np.random.default_rng(seed=42)
14+
total = rng.integers(n, n * max_val + 1)
15+
rows = np.zeros(n, dtype=np.uint64)
16+
cols = np.zeros(n, dtype=np.uint64)
17+
while True:
18+
rows = rng.multinomial(total, np.ones(n) / n)
19+
cols = rng.multinomial(total, np.ones(n) / n)
20+
if np.all(rows <= max_val) and np.all(cols <= max_val):
21+
break
22+
return rows, cols
23+
24+
25+
n = 10
26+
matrix = generate_random_unitary(n)
27+
rows, cols = generate_multiplicity_vectors(n)
28+
29+
data = {
30+
"matrix": matrix,
31+
"rows": rows,
32+
"cols": cols,
33+
}
34+
35+
np.save("example_data.npy", data)
36+
37+
loaded = np.load("example_data.npy", allow_pickle=True).item()
38+
print("Matrix:\n", loaded["matrix"])
39+
print("Rows:", loaded["rows"])
40+
print("Cols:", loaded["cols"])

0 commit comments

Comments
 (0)