Skip to content

Update Clements decomposition for unitary matrices#160

Open
Hugh-888 wants to merge 4 commits intoTuringQ:mainfrom
Hugh-888:dev/decompose
Open

Update Clements decomposition for unitary matrices#160
Hugh-888 wants to merge 4 commits intoTuringQ:mainfrom
Hugh-888:dev/decompose

Conversation

@Hugh-888
Copy link
Copy Markdown
Collaborator

@Hugh-888 Hugh-888 commented Apr 28, 2026

Update Clements decomposition for unitary matrices

  • case1
nmode = 6
u = unitary_group.rvs(nmode, random_state=20)
method = 'cssr'

ud = dq.photonic.UnitaryDecomposer(u, method)
test = ud.decomp()

dic_mzi = test[2]
cir = dq.Clements(nmode=nmode, init_state=[0,1,0,1,0,0], cutoff=3, phi_first=True)
data_new = cir.dict2data(dic_mzi)
u_check = cir(data=data_new)
print('error:', abs(u_check- torch.tensor(u))) 
image
  • case2
nmode = 6
u = unitary_group.rvs(nmode, random_state=20)
method = 'cssr'
batch = 2
u_ts = torch.tensor(u).repeat(batch, 1, 1)
ud = dq.photonic.UnitaryDecomposer(u_ts, method)
test1 = ud.decomp()

dic_mzi = test1[2]
cir = dq.Clements(nmode=nmode, init_state=[0]*nmode, cutoff=2)

data_new = cir.dict2data(dic_mzi).reshape(-1, batch).mT
u_check = cir(data=data_new)
print('error:', abs(u_check- torch.tensor(u)))
image
  • case3
nmode = 8
u = unitary_group.rvs(nmode)
method = 'cssl'
batch = 2
u_ts = torch.tensor(u).repeat(batch, 1, 1)
ud = dq.photonic.UnitaryDecomposer(u_ts, method)
test1 = ud.decomp()

dic_mzi = test1[2]
cir = dq.Clements(nmode=nmode, init_state=[0]*nmode, cutoff=2, phi_first=False)

data_new = cir.dict2data(dic_mzi).reshape(-1, batch).mT
u_check = cir(data=data_new)
error = abs(u_check- torch.tensor(u))
print('error:', torch.sum(error, dim=[1,2]))
cir.draw()
image

@Hugh-888 Hugh-888 added the enhancement New feature or request label May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant