qsim

Summary

Enumerations

GateAnyKind enum
GateKind enum

Typedefs

Bitstring using
uint64_t
For using
GateQSim using
Gate < fp_type, GateKind >
Matrix using
std::vector< fp_type >
Gate matrix type.
ParallelFor using
Simulator using
schmidt_decomp_type using
std::vector< std::vector< std::vector< fp_type >>>

Functions

ApplyFusedGate (const Simulator & simulator, const Gate & gate, typename Simulator::State & state)
void
Applies the given fused gate to the simulator state.
ApplyFusedGate (const typename Simulator::StateSpace & state_space, const Simulator & simulator, const Gate & gate, Rgen & rgen, typename Simulator::State & state, std::vector< typename Simulator::StateSpace::MeasurementResult > & mresults)
bool
Applies the given fused gate to the simulator state.
ApplyFusedGate (const typename Simulator::StateSpace & state_space, const Simulator & simulator, const Gate & gate, Rgen & rgen, typename Simulator::State & state)
bool
Applies the given fused gate to the simulator state, discarding measurement results.
ApplyFusedGateDagger (const Simulator & simulator, const Gate & gate, typename Simulator::State & state)
void
Applies the given fused gate dagger to the simulator state.
ApplyGate (const Simulator & simulator, const Gate & gate, typename Simulator::State & state)
void
Applies the given gate to the simulator state.
ApplyGate (const typename Simulator::StateSpace & state_space, const Simulator & simulator, const Gate & gate, Rgen & rgen, typename Simulator::State & state, std::vector< typename Simulator::StateSpace::MeasurementResult > & mresults)
bool
Applies the given gate to the simulator state.
ApplyGate (const typename Simulator::StateSpace & state_space, const Simulator & simulator, const Gate & gate, Rgen & rgen, typename Simulator::State & state)
bool
Applies the given gate to the simulator state, discarding measurement results.
ApplyGateDagger (const Simulator & simulator, const Gate & gate, typename Simulator::State & state)
void
Applies the given gate dagger to the simulator state.
BitstringsFromFile (unsigned num_qubits, const std::string & file, std::vector< Bitstring > & bitstrings)
bool
Reads bitstrings (representing initialized or measured states of qubits) from the given file and stores them in a vector.
BitstringsFromStream (unsigned num_qubits, const std::string & provider, Stream & fs, std::vector< Bitstring > & bitstrings)
bool
Reads bitstrings (representing initialized or measured states of qubits) from a provided stream object and stores them in a vector.
CalculateFusedMatrix (const FusedGate & gate)
Matrix< fp_type >
Multiplies component gate matrices of a fused gate.
CreateGate (unsigned time, Qubits && qubits, M && matrix, std::vector< typename Gate::fp_type > && params)
GenerateRandomValues (uint64_t num_samples, unsigned seed, DistrRealType max_value)
std::vector< DistrRealType >
GetSchmidtDecomp (GateKind kind, const std::vector< fp_type > & params)
schmidt_decomp_type< fp_type >
GetSchmidtDecomp (Cirq::GateKind kind, const std::vector< fp_type > & params)
schmidt_decomp_type< fp_type >
GetSchmidtDecomp (GateKind kind, const std::vector< fp_type > & params)
schmidt_decomp_type< fp_type >
GetTime ()
double
MakeControlledGate (Qubits && controlled_by, Gate & gate)
MakeControlledGate (Qubits && controlled_by, const std::vector< unsigned > & control_values, Gate & gate)
MatrixClear (Matrix< fp_type > & m)
void
Sets all matrix elements to zero.
MatrixDagger (unsigned n, Matrix< fp_type > & m)
void
Daggers a matrix.
MatrixIdentity (unsigned n, Matrix< fp_type > & m)
void
Sets an identity matrix.
MatrixMultiply (unsigned q, const Matrix< fp_type1 > & m1, Matrix< fp_type2 > & m2)
void
Multiplies two gate matrices of equal size: m2 = m1 m2.
MatrixMultiply (unsigned mask1, unsigned q1, const Matrix< fp_type1 > & m1, unsigned q2, Matrix< fp_type2 > & m2)
void
Multiplies two gate matrices: m2 = m1 m2.
MatrixScalarMultiply (fp_type1 c, Matrix< fp_type2 > & m)
void
Multiply a matrix by a scalar value.
MatrixShuffle (const std::vector< unsigned > & perm, unsigned q, Matrix< fp_type > & m)
void
Shuffles the gate matrix elements to get the matrix that acts on qubits that are in "normal" order (in increasing orger).
NormalToGateOrderPermutation (const std::vector< unsigned > & qubits)
std::vector< unsigned >
Gets a permutation to rearrange qubits from "normal" order to "gate" order.
RandomValue (RGen & rgen, DistrRealType max_value)
DistrRealType
SplitString (const std::string & str, char delim, Container & words)
void
SplitString (const std::string & str, char delim, Op op, Container & words)
void

Classes

qsim:: BasicGateFuser

Stateless object with methods for aggregating Gate s into GateFused .

qsim:: CircuitQsimParser

Parser for the (deprecated) qsim file input format .

qsim:: Fuser

A base class for fuser classes with some common functions.

qsim:: SimulatorAVX

Quantum circuit simulator with AVX vectorization.

qsim:: SimulatorBasic

Quantum circuit simulator without vectorization.

qsim:: SimulatorSSE

Quantum circuit simulator with SSE vectorization.

qsim:: StateSpace

Abstract class containing context and routines for general state-vector manipulations.

qsim:: StateSpaceAVX

Object containing context and routines for AVX state-vector manipulations.

qsim:: StateSpaceBasic

Object containing context and routines for unoptimized state-vector manipulations.

qsim:: StateSpaceSSE

Object containing context and routines for SSE state-vector manipulations.

Structs

qsim:: Circuit

A collection of gates.

qsim:: Gate

A generic gate to make it easier to use qsim with external gate sets.

qsim:: GateCNot

The controlled-X (CX or CNOT) gate.

qsim:: GateCP

The controlled phase gate.

qsim:: GateCZ

The controlled-Z (CZ) gate.

qsim:: GateFS

The fermionic simulation (FSim) gate family.

qsim:: GateFused

A collection of "fused" gates which can be multiplied together before being applied to the state vector.

qsim:: GateHZ2

A pi / 2 rotation around the X + Y axis.

qsim:: GateHd

The Hadamard gate.

qsim:: GateIS

The ISWAP gate.

qsim:: GateId1

The one-qubit identity gate.

qsim:: GateId2

The two-qubit identity gate.

qsim:: GateRX

A gate that rotates around the X axis of the Bloch sphere.

qsim:: GateRXY

A gate that rotates around an arbitrary axis in the XY-plane.

qsim:: GateRY

A gate that rotates around the Y axis of the Bloch sphere.

qsim:: GateRZ

A gate that rotates around the Z axis of the Bloch sphere.

qsim:: GateS

The S gate, equivalent to "square root of Z".

qsim:: GateSwap

The SWAP gate.

qsim:: GateT

The T gate, equivalent to Z ^ 0.25 .

qsim:: GateX

The Pauli X (or "NOT") gate.

qsim:: GateX2

The "square root of X" gate.

qsim:: GateY

The Pauli Y gate.

qsim:: GateY2

The "square root of Y" gate.

qsim:: GateZ

The Pauli Z gate.

qsim:: HybridSimulator

Hybrid Feynman-Schrodinger simulator.

qsim:: IO

Controller for output logs.

qsim:: IOFile

Controller for output logs with methods for writing to file.

qsim:: ParallelForT

Helper struct for executing for-loops in parallel across multiple threads.

qsim:: QSimHRunner

Helper struct for running qsimh.

qsim:: QSimRunner

Helper struct for running qsim.

qsim:: SequentialFor

Helper struct for executing for loops in series.

Namespaces

qsim:: Cirq
qsim:: detail
qsim:: gate
qsim:: unitary

Enumerations

GateAnyKind

 GateAnyKind

GateKind

 GateKind

Typedefs

Bitstring

uint64_t Bitstring

For

SequentialFor For

GateQSim

Gate< fp_type, GateKind > GateQSim

Matrix

std::vector< fp_type > Matrix

Gate matrix type.

Matrices are stored as vectors. The matrix elements are accessed as real(m[i][j]) <- vector[2 * (n * i + j)] and imag(m[i][j]) <- vector[2 * (n * i + j) + 1], where n is the number of rows or columns (n = 2^q, where q is the number of gate qubits).

ParallelFor

ParallelForT< 1024 > ParallelFor

Simulator

SimulatorBasic< For > Simulator

schmidt_decomp_type

std::vector< std::vector< std::vector< fp_type >>> schmidt_decomp_type

Functions

ApplyFusedGate

void ApplyFusedGate(
  const Simulator & simulator,
  const Gate & gate,
  typename Simulator::State & state
)

Applies the given fused gate to the simulator state.

Ignores measurement gates.

Details
Parameters
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
state
The state of the system, to be updated by this method.

ApplyFusedGate

bool ApplyFusedGate(
  const typename Simulator::StateSpace & state_space,
  const Simulator & simulator,
  const Gate & gate,
  Rgen & rgen,
  typename Simulator::State & state,
  std::vector< typename Simulator::StateSpace::MeasurementResult > & mresults
)

Applies the given fused gate to the simulator state.

Details
Parameters
state_space
StateSpace object required to perform measurements.
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
rgen
Random number generator to perform measurements.
state
The state of the system, to be updated by this method.
mresults
As an input parameter, this can be empty or this can contain the results of the previous measurements. If gate is a measurement gate then after a successful run, the measurement result will be added to this.
Returns
True if the measurement performed successfully; false otherwise.

ApplyFusedGate

bool ApplyFusedGate(
  const typename Simulator::StateSpace & state_space,
  const Simulator & simulator,
  const Gate & gate,
  Rgen & rgen,
  typename Simulator::State & state
)

Applies the given fused gate to the simulator state, discarding measurement results.

Details
Parameters
state_space
StateSpace object required to perform measurements.
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
rgen
Random number generator to perform measurements.
state
The state of the system, to be updated by this method.
Returns
True if the measurement performed successfully; false otherwise.

ApplyFusedGateDagger

void ApplyFusedGateDagger(
  const Simulator & simulator,
  const Gate & gate,
  typename Simulator::State & state
)

Applies the given fused gate dagger to the simulator state.

If the gate matrix is unitary then this is equivalent to applying the inverse gate. Ignores measurement gates.

Details
Parameters
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
state
The state of the system, to be updated by this method.

ApplyGate

void ApplyGate(
  const Simulator & simulator,
  const Gate & gate,
  typename Simulator::State & state
)

Applies the given gate to the simulator state.

Ignores measurement gates.

Details
Parameters
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
state
The state of the system, to be updated by this method.

ApplyGate

bool ApplyGate(
  const typename Simulator::StateSpace & state_space,
  const Simulator & simulator,
  const Gate & gate,
  Rgen & rgen,
  typename Simulator::State & state,
  std::vector< typename Simulator::StateSpace::MeasurementResult > & mresults
)

Applies the given gate to the simulator state.

Details
Parameters
state_space
StateSpace object required to perform measurements.
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
rgen
Random number generator to perform measurements.
state
The state of the system, to be updated by this method.
mresults
As an input parameter, this can be empty or this can contain the results of the previous measurements. If gate is a measurement gate then after a successful run, the measurement result will be added to this.
Returns
True if the measurement performed successfully; false otherwise.

ApplyGate

bool ApplyGate(
  const typename Simulator::StateSpace & state_space,
  const Simulator & simulator,
  const Gate & gate,
  Rgen & rgen,
  typename Simulator::State & state
)

Applies the given gate to the simulator state, discarding measurement results.

Details
Parameters
state_space
StateSpace object required to perform measurements.
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
rgen
Random number generator to perform measurements.
state
The state of the system, to be updated by this method.
Returns
True if the measurement performed successfully; false otherwise.

ApplyGateDagger

void ApplyGateDagger(
  const Simulator & simulator,
  const Gate & gate,
  typename Simulator::State & state
)

Applies the given gate dagger to the simulator state.

If the gate matrix is unitary then this is equivalent to applying the inverse gate. Ignores measurement gates.

Details
Parameters
simulator
Simulator object. Provides specific implementations for applying gates.
gate
The gate to be applied.
state
The state of the system, to be updated by this method.

BitstringsFromFile

bool BitstringsFromFile(
  unsigned num_qubits,
  const std::string & file,
  std::vector< Bitstring > & bitstrings
)

Reads bitstrings (representing initialized or measured states of qubits) from the given file and stores them in a vector.

Details
Parameters
num_qubits
Number of qubits represented in each bitstring.
file
The name of the file to read bitstrings from.
bitstrings
Output vector of bitstrings. On success, this will contain all bitstrings read in from 'file'.
Returns
True if reading succeeded; false otherwise.

BitstringsFromStream

bool BitstringsFromStream(
  unsigned num_qubits,
  const std::string & provider,
  Stream & fs,
  std::vector< Bitstring > & bitstrings
)

Reads bitstrings (representing initialized or measured states of qubits) from a provided stream object and stores them in a vector.

Details
Parameters
num_qubits
Number of qubits represented in each bitstring.
provider
Source of bitstrings; only used for error reporting.
fs
The stream to read bitstrings from.
bitstrings
Output vector of bitstrings. On success, this will contain all bitstrings read in from 'fs'.
Returns
True if reading succeeded; false otherwise.

CalculateFusedMatrix

Matrix< fp_type > CalculateFusedMatrix(
  const FusedGate & gate
)

Multiplies component gate matrices of a fused gate.

Details
Parameters
gate
Fused gate.
Returns
Matrix product of component matrices.

CreateGate

Gate CreateGate(
  unsigned time,
  Qubits && qubits,
  M && matrix,
  std::vector< typename Gate::fp_type > && params
)

GenerateRandomValues

std::vector< DistrRealType > GenerateRandomValues(
  uint64_t num_samples,
  unsigned seed,
  DistrRealType max_value
)

GetSchmidtDecomp

schmidt_decomp_type< fp_type > GetSchmidtDecomp(
  GateKind kind,
  const std::vector< fp_type > & params
)

GetSchmidtDecomp

schmidt_decomp_type< fp_type > GetSchmidtDecomp(
  Cirq::GateKind kind,
  const std::vector< fp_type > & params
)

GetSchmidtDecomp

schmidt_decomp_type< fp_type > GetSchmidtDecomp(
  GateKind kind,
  const std::vector< fp_type > & params
)

GetTime

double GetTime()

MakeControlledGate

Gate & MakeControlledGate(
  Qubits && controlled_by,
  Gate & gate
)

MakeControlledGate

Gate & MakeControlledGate(
  Qubits && controlled_by,
  const std::vector< unsigned > & control_values,
  Gate & gate
)

MatrixClear

void MatrixClear(
  Matrix< fp_type > & m
)

Sets all matrix elements to zero.

Matrix to be cleared.

MatrixDagger

void MatrixDagger(
  unsigned n,
  Matrix< fp_type > & m
)

Daggers a matrix.


Number of matrix rows (columns). Input matrix. Output matrix.

MatrixIdentity

void MatrixIdentity(
  unsigned n,
  Matrix< fp_type > & m
)

Sets an identity matrix.


Number of matrix rows (columns). Output identity matrix.

MatrixMultiply

void MatrixMultiply(
  unsigned q,
  const Matrix< fp_type1 > & m1,
  Matrix< fp_type2 > & m2
)

Multiplies two gate matrices of equal size: m2 = m1 m2.

Number of gate qubits. The number of matrix rows (columns) is 2^q. Matrix m1. Input matrix m2. Output product of matrices m2 = m1 m2.

MatrixMultiply

void MatrixMultiply(
  unsigned mask1,
  unsigned q1,
  const Matrix< fp_type1 > & m1,
  unsigned q2,
  Matrix< fp_type2 > & m2
)

Multiplies two gate matrices: m2 = m1 m2.

The size of m1 should not exceed the size of m2. Qubit mask that specifies the subset of qubits m1 acts on. Number of gate qubits. The number of matrix rows (columns) is 2^q1. Matrix m1. Number of gate qubits. The number of matrix rows (columns) is 2^q2. Input matrix m2. Output product of matrices m2 = m1 m2.

MatrixScalarMultiply

void MatrixScalarMultiply(
  fp_type1 c,
  Matrix< fp_type2 > & m
)

Multiply a matrix by a scalar value.

Scalar value. Input matrix to be multiplied. Output matrix.

MatrixShuffle

void MatrixShuffle(
  const std::vector< unsigned > & perm,
  unsigned q,
  Matrix< fp_type > & m
)

Shuffles the gate matrix elements to get the matrix that acts on qubits that are in "normal" order (in increasing orger).

Permutation to rearrange qubits from "normal" order to "gate" order. Number of gate qubits. The number of matrix rows (columns) is 2^q. Input matrix. Output shuffled matrix.

NormalToGateOrderPermutation

std::vector< unsigned > NormalToGateOrderPermutation(
  const std::vector< unsigned > & qubits
)

Gets a permutation to rearrange qubits from "normal" order to "gate" order.

Qubits are ordered in increasing order for "normal" order. Qubits are ordered arbitrarily for "gate" order. Returns an empty vector if the qubits are in "normal" order. Qubit indices in "gate" order.

Details
Returns
Permutation as a vector.

RandomValue

DistrRealType RandomValue(
  RGen & rgen,
  DistrRealType max_value
)

SplitString

void SplitString(
  const std::string & str,
  char delim,
  Container & words
)

SplitString

void SplitString(
  const std::string & str,
  char delim,
  Op op,
  Container & words
)