Gate
public struct Gate
extension Gate: QuantumOperatorConvertible
extension Gate: SimplifiedQuantumOperatorConvertible
extension Gate: SimplifiedGateConvertible
extension Gate: Hashable
A generic quantum gate
-
Declaration
Swift
public var quantumOperator: QuantumOperator { get }
-
Declaration
Swift
public var simplifiedQuantumOperator: SimplifiedQuantumOperator { get }
-
Returns a generic quantum
gate
controlled withcontrols
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
-
Errors throwed by
See moreGate.makeInversionAboutMean(inputs:)
Declaration
Swift
public enum MakeInversionAboutMeanError : Error
-
Buils a
Gate.matrix(matrix:inputs:)
gate that produces an inversion about the mean on the giveninputs
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 ofinputs
(as many inputs asmatrix
is able to handle)Declaration
Swift
public static func matrix(matrix: Matrix, inputs: [Int]) -> Gate
-
Errors throwed by
See moreGate.makeModularExponentiation(base:modulus:exponent:inputs:)
Declaration
Swift
public enum MakeModularExponentiationError : Error
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
. Whilebase
&modulus
are constant integers,exponent
is a list of qubits and, therefore, its actual value can vary. The extrainputs
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 Ifexponent
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 tomodulus
- 1). Also, in order to get the expected result at the end of the list ofGate
instances, the input qubits have to be set to |1>. For example, ifinputs
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, ifinputs
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. OrMakeModularExponentiationError
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 whichcontrols
activate agate
Declaration
Swift
public static func oracle(truthTable: [String], controls: [Int], gate: Gate) -> Gate
-
Produces a
Gate.oracle(truthTable:controls:gate:)
with aGate.not(target:)
in target.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
byradians
Declaration
Swift
public static func phaseShift(radians: Double, target: Int) -> Gate
-
Errors throwed by
See moreGate.makeQuantumFourierTransform(inputs:inverse:)
Declaration
Swift
public enum MakeQuantumFourierTransformError : Error
-
Buils a
Gate.matrix(matrix:inputs:)
gate that performs a Quantum Fourier Transform overinputs
ifinverse
isfalse
or an inverse Quantum Fourier Transform otherwiseDeclaration
Swift
public static func makeQuantumFourierTransform(inputs: [Int], inverse: Bool = false) -> Result<Gate, MakeQuantumFourierTransformError>
-
Returns a quantum gate that defines a rotation of
radians
aroundaxis
of the quantum state intarget
Declaration
Swift
public static func rotation(axis: Axis, radians: Double, target: Int) -> Gate
-
Declaration
Swift
public var simplifiedGate: SimplifiedGate { get }
-
Builds a
Gate.matrix(matrix:inputs:)
gate that produces an inversion about the mean onDeclaration
Swift
public static func makeInversionAboutMean(inputs: Range<Int>) -> Result<Gate, MakeInversionAboutMeanError>
-
Builds a
Gate.matrix(matrix:inputs:)
gate that produces an inversion about the mean onDeclaration
Swift
public static func makeInversionAboutMean(inputs: ClosedRange<Int>) -> Result<Gate, MakeInversionAboutMeanError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: Range<Int>, inputs: [Int]) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: ClosedRange<Int>, inputs: [Int]) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: [Int], inputs: Range<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: [Int], inputs: ClosedRange<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: Range<Int>, inputs: Range<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: Range<Int>, inputs: ClosedRange<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: ClosedRange<Int>, inputs: Range<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Implements with
Gate
instances a modular exponentiation performed overmodulus
withbase
raised toexponent
Declaration
Swift
public static func makeModularExponentiation(base: Int, modulus: Int, exponent: ClosedRange<Int>, inputs: ClosedRange<Int>) -> Result<[Gate], MakeModularExponentiationError>
-
Produces an oracle gate
Declaration
Swift
public static func oracle(truthTable: [String], controls: Range<Int>, gate: Gate) -> Gate
-
Produces an oracle gate
Declaration
Swift
public static func oracle(truthTable: [String], controls: ClosedRange<Int>, gate: Gate) -> Gate
-
Produces an oracle gate
Declaration
Swift
public static func oracle(truthTable: [String], controls: Range<Int>, target: Int) -> Gate
-
Produces an oracle gate
Declaration
Swift
public static func oracle(truthTable: [String], controls: ClosedRange<Int>, target: Int) -> Gate
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: [Int], targets: Range<Int>) -> [Gate]
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: Range<Int>, targets: Range<Int>) -> [Gate]
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: ClosedRange<Int>, targets: Range<Int>) -> [Gate]
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: [Int], targets: ClosedRange<Int>) -> [Gate]
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: Range<Int>, targets: ClosedRange<Int>) -> [Gate]
-
Produces a list of oracle gates
Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: ClosedRange<Int>, targets: ClosedRange<Int>) -> [Gate]
-
Produces a list of
Gate.hadamard(target:)
, each gate on one of thetargets
Declaration
Swift
public static func hadamard(targets: Range<Int>) -> [Gate]
-
Produces a list of
Gate.hadamard(target:)
, each gate on one of thetargets
Declaration
Swift
public static func hadamard(targets: ClosedRange<Int>) -> [Gate]
-
Produces a list of
Gate.hadamard(target:)
, each gate on one of thetargets
Declaration
Swift
public static func hadamard(targets: Int...) -> [Gate]
-
Produces a list of
Gate.not(target:)
, each gate on one of thetargets
Declaration
Swift
public static func not(targets: Range<Int>) -> [Gate]
-
Produces a list of
Gate.not(target:)
, each gate on one of thetargets
Declaration
Swift
public static func not(targets: ClosedRange<Int>) -> [Gate]
-
Produces a list of
Gate.not(target:)
, each gate on one of thetargets
Declaration
Swift
public static func not(targets: Int...) -> [Gate]
-
Represents the
activation
(or bits) produded by a function after inputting a giventruth
Declaration
Swift
public typealias ExtendedTruth = (truth: String, activation: String)
-
Produces a list of
Gate.oracle(truthTable:controls:gate:)
. AGate.not(target:)
is produced for each target intargets
if at least oneactivation
intruthTable
has the bit correspoding to the target activated.Declaration
Swift
public static func oracle(truthTable: [ExtendedTruth], controls: [Int], targets: [Int]) -> [Gate]
Parameters
truthTable
List of
Gate.ExtendedTruth
instances.controls
Control qubits for each oracle in the list.
targets
Targets for each oracle in the list.
Return Value
-
Produces a list of
Gate.hadamard(target:)
, each gate on one of thetargets
Declaration
Swift
public static func hadamard(targets: [Int]) -> [Gate]
-
Produces a list of
Gate.not(target:)
, each gate on one of thetargets
Declaration
Swift
public static func not(targets: [Int]) -> [Gate]
-
Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)