Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
/ YaoToEinsum.jl Public archive

Convert Yao circuit to OMEinsum (tensor network) contraction.

License

Notifications You must be signed in to change notification settings

QuantumBFS/YaoToEinsum.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YaoToEinsum

CI codecov

Convert Yao circuit to tensor networks (einsum).

Installation

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

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.

  • initial_state and final_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 is TreeSA(). 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

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.