gate

package
v0.0.0-...-c1fb209 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CNOT

func CNOT(bit, c, t int) matrix.Matrix

func CR

func CR(bit, c, t, k int) matrix.Matrix

func CS

func CS(bit, c, t int) matrix.Matrix

func CZ

func CZ(bit, c, t int) matrix.Matrix

func ControlledNot

func ControlledNot(bit int, c []int, t int) matrix.Matrix

ControlledNot returns the matrix resulting from a CNOT gate which flips the second qubit (t the target qubit) if and only if the first qubit (c the control qubit) is |1>

Example
package main

import (
	"fmt"

	"github.com/axamon/q/gate"
)

func main() {
	mCN := gate.ControlledNot(2, []int{1}, 1)
	for _, r := range mCN {
		fmt.Println(r)
	}
}
Output:

[(1+0i) (0+0i) (0+0i) (0+0i)]
[(1+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]

func ControlledR

func ControlledR(bit int, c []int, t, k int) matrix.Matrix

func ControlledS

func ControlledS(bit int, c []int, t int) matrix.Matrix

func ControlledZ

func ControlledZ(bit int, c []int, t int) matrix.Matrix

func Fredkin

func Fredkin() matrix.Matrix

Fredkin returns the 8x8 Fredkin matrix.

Example
package main

import (
	"fmt"

	"github.com/axamon/q/gate"
)

func main() {
	f := gate.Fredkin()
	for _, r := range f {
		fmt.Println(r)
	}
}
Output:

[(1+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (1+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (1+0i) (0+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (0+0i) (1+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (1+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (0+0i) (1+0i)]

func H

func H(bit ...int) matrix.Matrix

H is the Hadamard gate it gives measurements equal possibilities to become 1 or 0 creating therefore superposition.

Example
package main

import (
	"fmt"

	"github.com/axamon/q"
)

func main() {
	qsim := q.New()

	// generate qubits of |0>|1>
	q0 := qsim.Zero()
	q1 := qsim.One()

	// apply quantum circuit
	qsim.H(q0)
	qsim.H(q1)
	// estimate
	result0 := qsim.Estimate(q0).Probability()
	fmt.Printf("%.1f\n", result0)
	result1 := qsim.Estimate(q1).Probability()
	fmt.Printf("%.1f\n", result1)
}
Output:

[0.5 0.5]
[0.5 0.5]

func I

func I(bit ...int) matrix.Matrix
Example
package main

import (
	"fmt"

	"github.com/axamon/q/gate"
)

func main() {
	m := gate.I(2)
	for _, r := range m {
		fmt.Println(r)
	}
}
Output:

[(1+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (1+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (0+0i) (0+0i) (1+0i)]

func New

func New(v ...[]complex128) matrix.Matrix

New creates a gate matrix made of complex inputs.

func QFT

func QFT(bit int) matrix.Matrix

QFT creates a Quantum Fourier Transformation matrix.

Example
package main

import (
	"fmt"

	"github.com/axamon/q/gate"
)

func main() {
	mQFT := gate.QFT(1)
	for _, r := range mQFT {
		fmt.Println(r)
	}
}
Output:

[(0.7071067811865476+0i) (0.7071067811865476+0i)]
[(0.7071067811865476+0i) (-0.7071067811865476+0i)]

func R

func R(k int) matrix.Matrix

func S

func S(bit ...int) matrix.Matrix

S is the phase gate.

Example
package main

import (
	"fmt"

	"github.com/axamon/q"
)

func main() {
	qsim := q.New()

	// generate qubits of |0>|1>
	q0 := qsim.Zero()
	q1 := qsim.One()

	qsim.S(q0)
	qsim.S(q1)

	result0 := qsim.Estimate(q0).Probability()
	fmt.Printf("%.1f\n", result0)
	result1 := qsim.Estimate(q1).Probability()
	fmt.Printf("%.1f\n", result1)
}
Output:

[1.0 0.0]
[0.0 1.0]

func Swap

func Swap(bit, c, t int) matrix.Matrix
Example
package main

import (
	"fmt"

	"github.com/axamon/q/gate"
)

func main() {
	m := gate.Swap(2, 1, 1)
	for _, r := range m {
		fmt.Println(r)
	}
}
Output:

[(1+0i) (0+0i) (0+0i) (0+0i)]
[(1+0i) (0+0i) (0+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]
[(0+0i) (0+0i) (1+0i) (0+0i)]

func T

func T(bit ...int) matrix.Matrix

T is the Pi/8 gate.

Example
package main

import (
	"fmt"

	"github.com/axamon/q"
)

func main() {
	qsim := q.New()

	// generate qubits of |0>|1>
	q0 := qsim.Zero()
	q1 := qsim.One()

	qsim.T(q0)
	qsim.T(q1)

	result0 := qsim.Estimate(q0).Probability()
	fmt.Printf("%.1f\n", result0)
	result1 := qsim.Estimate(q1).Probability()
	fmt.Printf("%.1f\n", result1)
}
Output:

[1.0 0.0]
[0.0 1.0]

func Toffoli

func Toffoli() matrix.Matrix

func U

func U(alpha, beta, gamma, delta float64) matrix.Matrix

func X

func X(bit ...int) matrix.Matrix

X is the Pauli-X gate equivalent to the NOT gate of classical computers.

func Y

func Y(bit ...int) matrix.Matrix

Y is the Pauli-Y gate it rotates pi radiants the blotch sphere around the y axis.

func Z

func Z(bit ...int) matrix.Matrix

Z is the Pauli-Z gate it rotates pi radiants the blotch sphere around the z axis.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL