Convert Yao circuit to tensor networks (einsum).
Warning
Moved to Yao.jl: https://github.com/QuantumBFS/Yao.jl/tree/master/lib/YaoToEinsum
YaoToEinsum
is a Julia language package. To install YaoToEinsum
, please open Julia's interactive session (known as REPL) and press ] key in the REPL to use the package mode, then type the following command
pkg> add YaoToEinsum
This package contains one main function yao2einsum(circuit; initial_state=Dict(), final_state=Dict(), optimizer=TreeSA())
.
It transform a Yao
circuit to a generalized tensor network (einsum notation). The return value is a TensorNetwork
object.
initial_state
andfinal_state
are for specifying the initial state and final state. If any of them is not specified, the function will return a tensor network with open legs.optimizer
is for optimizing the YaoToEinsum.contraction order of the tensor network. The default value isTreeSA()
. Please check the README of OMEinsumYaoToEinsum.contractors.jl for more information.
julia> import Yao, YaoToEinsum
julia> using Yao.EasyBuild: qft_circuit
julia> using YaoToEinsum: TreeSA
julia> n = 10;
julia> circuit = qft_circuit(n);
# convert this circuit to tensor network
julia> network = YaoToEinsum.yao2einsum(circuit)
TensorNetwork
Time complexity: 2^20.03816881914695
Space complexity: 2^20.0
Read-write complexity: 2^20.07564105083201
julia> reshape(YaoToEinsum.contract(network), 1<<n, 1<<n) ≈ Yao.mat(circuit)
true
# convert circuit sandwiched by zero states
julia> network = YaoToEinsum.yao2einsum(circuit;
initial_state=Dict([i=>0 for i=1:n]), final_state=Dict([i=>0 for i=1:n]),
optimizer=TreeSA(; nslices=3)) # slicing technique
TensorNetwork
Time complexity: 2^12.224001674198101
Space complexity: 2^5.0
Read-write complexity: 2^13.036173612553485
julia> YaoToEinsum.contract(network)[] ≈ Yao.zero_state(n)' * (Yao.zero_state(n) |> circuit)
true
If you have any questions or suggestions, please feel free to open an issue or pull request. If you use this package in your work, please cite the relevant part of the papers included in CITATION.bib.