Gate

public struct Gate
extension Gate: QuantumOperatorConvertible
extension Gate: SimplifiedQuantumOperatorConvertible
extension Gate: SimplifiedGateConvertible
extension Gate: Hashable

A generic quantum gate

QuantumOperatorConvertible methods

SimplifiedQuantumOperatorConvertible methods

Public class methods

  • Returns a generic quantum gate controlled with controls

    Declaration

    Swift

    public static func controlled(gate: Gate, controls: [Int]) -> Gate
  • Returns a controlled not gate with 2 inputs: target & control

    Declaration

    Swift

    public static func controlledNot(target: Int, control: Int) -> Gate
  • Returns a hadamard gate with 1 input: target

    Declaration

    Swift

    public static func hadamard(target: Int) -> Gate
  • Declaration

    Swift

    public enum MakeInversionAboutMeanError : Error
  • Buils a Gate.matrix(matrix:inputs:) gate that produces an inversion about the mean on the given inputs

    Declaration

    Swift

    public static func makeInversionAboutMean(inputs: [Int]) -> Result<Gate, MakeInversionAboutMeanError>
  • Returns a generic quantum gate built with a matrix (it is expected to be unitary) and any number of inputs (as many inputs as matrix is able to handle)

    Declaration

    Swift

    public static func matrix(matrix: Matrix, inputs: [Int]) -> Gate
  • Declaration

    Swift

    public enum MakeModularExponentiationError : Error
  • Implements with Gate instances a modular exponentiation performed over modulus with base raised to exponent. While base & modulus are constant integers, exponent is a list of qubits and, therefore, its actual value can vary. The extra inputs are used to pass the result from one gate to the next and they HAVE TO be set to |1>.

    Declaration

    Swift

    public static func makeModularExponentiation(base: Int,
                                                 modulus: Int,
                                                 exponent: [Int],
                                                 inputs: [Int]) -> Result<[Gate], MakeModularExponentiationError>

    Parameters

    base

    Base of the modular exponentiation, a positive integer bigger than zero.

    modulus

    Modulus of the modular exponentiation, a positive integer bigger than zero..

    exponent

    List of qubits that defines the exponent of the modular exponentiation. For example, if exponent is equal to [2, 1, 0] and qubit[2]=1, qubit[1]=1 & qubit[0]=0, the actual value of the exponent is ‘110’=6. Notice that If exponent was reveresed (i.e. [0, 1, 2]), the actual of the exponent would be ‘011’=3.

    inputs

    List of qubits used to pass the result from one gate to the next. Notice that, because this is a modulo, you have to provide at least enough input qubits to code modulus values (from 0 to modulus - 1). Also, in order to get the expected result at the end of the list of Gate instances, the input qubits have to be set to |1>. For example, if inputs are equal to [2, 1, 0], qubit[2] and qubit[1] have to be 0 and qubit[0] has to be 1. On the other hand, if inputs were [0, 1, 2], qubit[0] and qubit[1] should be 0 and qubit[2] should be 1.

    Return Value

    List of Gate instances that code a modular exponentiation. Or MakeModularExponentiationError error.

  • Returns a not gate with 1 input: target

    Declaration

    Swift

    public static func not(target: Int) -> Gate
  • Returns an oracle gate composed of a truthtable that specifies which controls activate a gate

    Declaration

    Swift

    public static func oracle(truthTable: [String], controls: [Int], gate: Gate) -> Gate
  • Declaration

    Swift

    public static func oracle(truthTable: [String], controls: [Int], target: Int) -> Gate

    Parameters

    truthTable

    Oracle truthtable.

    controls

    Control qubits.

    target

    Target of Gate.not(target:).

    Return Value

    A Gate.oracle(truthTable:controls:gate:) instance.

  • Returns a quantum gate that shifts phase of the quantum state in target by radians

    Declaration

    Swift

    public static func phaseShift(radians: Double, target: Int) -> Gate
  • Declaration

    Swift

    public enum MakeQuantumFourierTransformError : Error
  • Buils a Gate.matrix(matrix:inputs:) gate that performs a Quantum Fourier Transform over inputs if inverse is false or an inverse Quantum Fourier Transform otherwise

    Declaration

    Swift

    public static func makeQuantumFourierTransform(inputs: [Int],
                                                   inverse: Bool = false) -> Result<Gate, MakeQuantumFourierTransformError>

Public types

  • Paulis P = {X, Y, Z}

    See more

    Declaration

    Swift

    public enum Axis

Public class methods

  • Returns a quantum gate that defines a rotation of radians around axis of the quantum state in target

    Declaration

    Swift

    public static func rotation(axis: Axis, radians: Double, target: Int) -> Gate

SimplifiedGateConvertible methods

Public class methods

Public types

  • Represents the activation (or bits) produded by a function after inputting a given truth

    Declaration

    Swift

    public typealias ExtendedTruth = (truth: String, activation: String)

Public class methods

Hashable methods

  • Declaration

    Swift

    public static func == (lhs: `Self`, rhs: `Self`) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)