# Abstract Registers

Quantum circuits process quantum states. A quantum state being processing by a quantum circuit will be stored on a quantum register. In Yao we provide several types for registers. The default type for registers is the ArrayReg which is defined in YaoArrayRegister.jl.

The registers can be extended by subtyping AbstractRegister and define correspinding register interfaces defined in YaoBase.jl, which includes:

## Minimal Required Interfaces

The following interfaces are the minial required interfaces to make a register's printing work and be able to accept certain gates/blocks.

But if you don't want to work with our default printing, you could define your custom printing with Base.show.

Missing docstring.

Missing docstring for YaoBase.nqubits. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.nactive. Check Documenter's build log for details.

you can define instruct!, to provide specialized instructions for the registers from plain storage types.

## Qubit Management Interfaces

Missing docstring.

Missing docstring for YaoBase.addbits!. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.reorder!. Check Documenter's build log for details.

## Qubit Scope Management Interfaces

### LDT format

Concepturely, a wave function $|\psi\rangle$ can be represented in a low dimentional tensor (LDT) format of order-3, L(f, r, b).

• f: focused (i.e. operational) dimensions
• r: remaining dimensions
• b: batch dimension.

For simplicity, let's ignore batch dimension for the now, we have

$|\psi\rangle = \sum\limits_{x,y} L(x, y, .) |j\rangle|i\rangle$

Given a configuration x (in operational space), we want get the i-th bit using (x<<i) & 0x1, which means putting the small end the qubit with smaller index. In this representation L(x) will get return $\langle x|\psi\rangle$.

Note

Why not the other convension: Using the convention of putting 1st bit on the big end will need to know the total number of qubits n in order to know such positional information.

### HDT format

Julia storage is column major, if we reshape the wave function to a shape of $2\times2\times ... \times2$ and get the HDT (high dimensional tensor) format representation H, we can use H($x_1, x_2, ..., x_3$) to get $\langle x|\psi\rangle$.

YaoAPI.focus!Function
focus(f, register, locs...)

Call a callable f under the context of focus. See also focus!.

Example

print the focused register

julia> r = ArrayReg(bit"101100")
ArrayReg{1,Complex{Float64},Array...}
active qubits: 6/6

julia> focus(x->(println(x);x), r, 1, 2);
ArrayReg{1,Complex{Float64},Array...}
active qubits: 2/6
source
focus!(locs...) -> f(register) -> register

Lazy version of focus!, this returns a lambda which requires a register.

source

## Measurement Interfaces

Missing docstring.

Missing docstring for YaoBase.measure. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.measure!. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.measure_remove!. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.measure_collapseto!. Check Documenter's build log for details.

## Others

YaoAPI.fidelityFunction
fidelity(r1::ArrayReg, r2::ArrayReg)

Calcuate the fidelity between r1 and r2, if r1 or r2 is not pure state (nactive(r) != nqubits(r)), the fidelity is calcuated by purification. See also pure_state_fidelity, purification_fidelity.

fidelity'(pair_or_reg1, pair_or_reg2) -> (g1, g2)

Obtain the gradient with respect to registers and circuit parameters. For pair input ψ=>circuit, the returned gradient is a pair of gψ=>gparams, with gψ the gradient of input state and gparams the gradients of circuit parameters. For register input, the return value is a register.

source
Missing docstring.

Missing docstring for YaoBase.tracedist. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.density_matrix. Check Documenter's build log for details.

Missing docstring.

Missing docstring for YaoBase.viewbatch. Check Documenter's build log for details.