https://github.com/quantumbfs/yaotoeinsum.jl
Convert Yao circuit to OMEinsum (tensor network) contraction.
https://github.com/quantumbfs/yaotoeinsum.jl
curcuit network quantum tensor
Last synced: 5 months ago
JSON representation
Convert Yao circuit to OMEinsum (tensor network) contraction.
- Host: GitHub
- URL: https://github.com/quantumbfs/yaotoeinsum.jl
- Owner: QuantumBFS
- License: mit
- Archived: true
- Created: 2021-11-07T00:58:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-11T04:35:42.000Z (almost 2 years ago)
- Last Synced: 2024-08-11T05:44:00.427Z (almost 2 years ago)
- Topics: curcuit, network, quantum, tensor
- Language: Julia
- Homepage:
- Size: 37.1 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.bib
Awesome Lists containing this project
README
# YaoToEinsum
[](https://github.com/QuantumBFS/YaoToEinsum.jl/actions)
[](https://codecov.io/gh/QuantumBFS/YaoToEinsum.jl)
Convert [Yao](https://github.com/QuantumBFS/Yao.jl) 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](https://julialang.org/) package. To install `YaoToEinsum`, please [open Julia's interactive session (known as REPL)](https://docs.julialang.org/en/v1/manual/getting-started/) and press ] key in the REPL to use the package mode, then type the following command
```julia
pkg> add YaoToEinsum
```
## Using
This package contains one main function `yao2einsum(circuit; initial_state=Dict(), final_state=Dict(), optimizer=TreeSA())`.
It transform a [`Yao`](https://github.com/QuantumBFS/Yao.jl) 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](https://github.com/TensorBFS/OMEinsumYaoToEinsum.contractionOrders.jl) for more information.
```julia
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< 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](CITATION.bib).