Package: qoptcraft
QOptCraftA Python package for the design and study of linear optical quantum systems.DocumentationDocumentation and examples can be foundhere.InstallationCreate and activate a new conda environmentconda create --name test python==3.11conda activate testClone the repositorygit clone -b optimized https://github.tel.uva.es/juagar/qoptcraft.gitInstall withpip:pip install git+https://github.tel.uva.es/juagar/qoptcraft.git@optimizedQuick usageClemens and Reck decompositionsWe can decompose any unitary into beamsplitters and phase shifters:fromqoptcraft.optical_elementsimportclemens_decomposition,reck_decompositionfromqoptcraft.operatorsimporthaar_random_unitarymodes=4unitary=haar_random_unitary(modes)left,diag,right=clemens_decomposition(unitary)diag,right=reck_decomposition(unitary)BasisWe can get easily get the basis of the unitary algebrafromqoptcraft.basisimportget_algebra_basismodes=2photons=3basis_algebra,basis_image_algebra=get_algebra_basis(modes,photons)or the Fock state basis of the Hilbert spacefromqoptcraft.basisimportget_photon_basis,hilbert_dimphoton_basis=get_photon_basis(modes,photons)dimension=hilbert_dim(modes,photons)# should equal len(photon_basis)StatesWe can create pure quantum states by summing Fock states:frommathimportsqrtfromqoptcraft.stateimportFockin_fock=Fock(1,1,0,0)bell_state=1/sqrt(2)*Fock(1,0,1,0)+1/sqrt(2)*Fock(0,1,0,1)InvariantsTo check if transitions between quantum states are forbidden by a linear optical transformation, we simply runfromqoptcraft.invariantimportforbidden_transition,photon_invariantforbidden_transition(in_fock,bell_state,method="reduced")>>> TrueThe invariant can be calculated from density matrices (calculations use the basis of the algebra)
To check if transitions between quantum states are forbidden by a linear optical transformation, we simply runfromqoptcraft.stateimportMixedStatefromqoptcraft.invariantimportforbidden_transition,photon_invariantmixed_state=MixedState.from_mixture(pure_states=[in_fock,bell_state],probs=[0.5,0.5])forbidden_transition(mixed_state,bell_state,method="basis")>>> TrueQuantizing linear interferomentersWe can easily compute the unitary matrix associated with a linear interferometer S and a certain number of photons. There are four different methods to compute the unitary:'heisenberg','hamiltonian','permanent glynn'and'permanent ryser'.fromqoptcraft.operatorsimporthaar_random_unitaryfromqoptcraft.evolutionimportphoton_unitarymodes=2photons=3interferometer=haar_random_unitary(modes)unitary_heisenberg=photon_unitary(interferometer,photons,method="heisenberg")unitary_hamiltonian=photon_unitary(interferometer,photons,method="hamiltonian")unitary_glynn=photon_unitary(interferometer,photons,method="permanent glynn")unitary_ryser=photon_unitary(interferometer,photons,method="permanent ryser")We can apply this function to a 50:50 beamsplitter to recover the Hong-Ou-Mandel matrixfromnumpyimportpiasPIfromqoptcraft.optical_elementsimportbeam_splitterbs_matrix=beam_splitter(angle=PI/4,shift=0,dim=2,mode_1=0,mode_2=1,convention="clemens")hong_ou_mandel=photon_unitary(bs_matrix,photons=3,method="heisenberg")Retrieve the linear optical scattering matrix from the quantized unitaryIf a given unitary matrix comes from a linear optical scattering matrix, we can retrieve itfromqoptcraftimporthaar_random_unitary,photon_unitary,scattering_from_unitarymodes=3photons=2S=haar_random_unitary(modes)U=photon_unitary(S,photons)S_rebuilt=scattering_from_unitary(U,modes,photons)If this scattering matrix doesn't exist, it will raise anInconsistentEquationserror.Approximating a unitary with linear optics (Topogonov)fromqoptcraft.operatorsimportqftfromqoptcraft.topogonovimporttopogonovmodes=3photons=2unitary=qft(6)approx_unitary,error=topogonov(unitary,modes,photons)CitingQOptCraft is the work of Daniel Gómez Aguado (gomezaguado99@gmail.com) and Pablo V. Parellada (pablo.veganzones@uva.es).If you are doing research using qoptcraft, please cite our paper:Daniel Gómez Aguado et al. qoptcraft: A Python package for the design and study of linear optical quantum systems. 2023. https://doi.org/10.1016/j.cpc.2022.108511References[1] W. R. Clements, P. C. Humphreys, B. J. Metcalf, W. S. Kolthammer, and I. A. Walsmley, ”Optimal Design for Universal Multiport Interferometers”, Optica 3, 1460 (2016).[2] J. Skaar, J. C. García Escartín, and H. Landro, ”Quantum mechanical description of linear optic”, American Journal of Physics 72, 1385 (2004).[3] S. Scheel, ”Permanents in linear optics network”, Acta Physica Slovaca 58, 675 (2008).[4] ”Permanents and Ryser’s algorithm”, numbersandshapes.net.[5] J. C. García Escartín, V. Gimeno, and J. J. Moyano-Fernández, ”Multiple photon effective Hamiltonians in linear quantum optical networks”, Optics Communications 430 (2019) 434–439.[6] J. C. García Escartín, V. Gimeno, and J. J. Moyano Fernández, ”A method to determine which quantum operations can be realized with linear optics with a constructive implementation recipe”, Physical Review A 100, 022301 (2019).[7] J. C. García Escartín and J. J. Moyano Fernández, ”Optimal approximation to unitary quantum operators with linear optics”, arXiv:2011.15048v1 [quant-ph].[8] N. Tischler, C. Rockstuhl, and K. Slowik, ”Quantum Optical Realization of Arbitrary Linear Transformations Allowing for Loss and Gain”, Physical Review X 8, 021017 (2018).[9] T. A. Loring, ”Computing a logarithm of a unitary matrix with general spectrum”, Numerical Linear Algebra wth Applications, 21 (6) 744–760 (2014).ContributingWe appreciate and welcome contributions. For major changes, please open an issue first
to discuss what you would like to change. Also, make sure to update tests as appropriate.If you are new to contributing to open source,this guidehelps explain why, what, and how to get involved.LicenseThis software is under theApache License 2.0.