Home

Awesome

YaoToEinsum

CI codecov

Convert Yao circuit to tensor networks (einsum).

[!warning] Moved to Yao.jl: https://github.com/QuantumBFS/Yao.jl/tree/master/lib/YaoToEinsum

Installation

YaoToEinsum is a Julia language package. To install YaoToEinsum, please open Julia's interactive session (known as REPL) and press <kbd>]</kbd> key in the REPL to use the package mode, then type the following command

pkg> add YaoToEinsum

Using

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.

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

Contribute and Cite

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.