Documentation ¶
Overview ¶
Package quantumsimulator provides structures and functions for simulating quantum gates and circuits.
Index ¶
- Variables
- func IdentityMatrix(n int) [][]complex128
- func Multiply(matrix [][]complex128, vector []complex128) []complex128
- type Circuit
- func (circuit *Circuit) ApplyGate(gate Gate, target int, control ...int) error
- func (circuit *Circuit) CU(control, target int, theta, phi, lambda float64, inv ...bool)
- func (circuit *Circuit) CX(control, target int, inv ...bool)
- func (circuit *Circuit) H(target int, inv ...bool)
- func (circuit *Circuit) PrintState()
- func (circuit *Circuit) Run(shots int) (map[string]int, error)
- func (circuit *Circuit) T(target int, inv ...bool)
- func (circuit *Circuit) U(target int, theta, phi, lambda float64, inv ...bool)
- func (circuit *Circuit) X(target int, inv ...bool)
- type Gate
Constants ¶
This section is empty.
Variables ¶
var ( H = NewGate([][]complex128{ {complex(1/math.Sqrt(2), 0), complex(1/math.Sqrt(2), 0)}, {complex(1/math.Sqrt(2), 0), complex(-1/math.Sqrt(2), 0)}, }) X = NewGate([][]complex128{ {complex(0, 0), complex(1, 0)}, {complex(1, 0), complex(0, 0)}, }) T = NewGate([][]complex128{ {complex(1, 0), complex(0, 0)}, {complex(0, 0), cmplx.Exp(complex(0, math.Pi/4))}, }) )
Predefined quantum gates.
Functions ¶
func IdentityMatrix ¶ added in v0.2.0
func IdentityMatrix(n int) [][]complex128
IdentityMatrix creates and returns an identity matrix of size n x n.
func Multiply ¶ added in v0.2.0
func Multiply(matrix [][]complex128, vector []complex128) []complex128
Multiply multiplies a matrix by a vector and returns the resulting vector.
Types ¶
type Circuit ¶
type Circuit struct { State []complex128 // The state vector of the circuit. // contains filtered or unexported fields }
Circuit struct represents a quantum circuit with multiple qubits. State holds the current state vector of the quantum circuit, and nQubits holds the total number of qubits in the circuit.
func NewCircuit ¶
NewCircuit initializes a new Circuit with nQubits and returns it. The function sets the initial state vector where only the first element is set to 1.
func (*Circuit) ApplyGate ¶
ApplyGate applies a quantum gate to the circuit. The method takes gate as the quantum gate to apply, target as the target qubit, and optional control qubits for controlled gates.
func (*Circuit) CU ¶ added in v1.1.0
CU applies a controlled-U gate to target qubits in the circuit, or its inverse if inv is true.
func (*Circuit) CX ¶
CX applies a controlled-X (CNOT) gate to target qubits in the circuit, or its inverse if inv is true.
func (*Circuit) H ¶
H applies a Hadamard gate to a target qubit in the circuit, or its inverse if inv is true.
func (*Circuit) PrintState ¶ added in v1.1.0
func (circuit *Circuit) PrintState()
PrintState prints the current quantum state and the probability of each state.
func (*Circuit) Run ¶
Run simulates the measurement of the quantum circuit multiple times. The method takes shots as the number of times the measurement is repeated, and returns a map with the measurement outcomes and their occurrences.
func (*Circuit) T ¶
T applies a T gate (π/8 gate) to a target qubit in the circuit, or its inverse if inv is true.
type Gate ¶
type Gate struct {
Matrix [][]complex128 // Matrix representation of the quantum gate.
}
Gate struct represents a quantum gate with its matrix representation.
func NewGate ¶
func NewGate(matrix [][]complex128) Gate
NewGate creates and returns a Gate instance with the provided matrix.
func U ¶ added in v1.0.0
U creates and returns a U Gate instance defined by the parameters theta, phi, and lambda.