16 # include <sys/param.h> 19 # include <sys/types.h> 20 # include <sys/time.h> 26 "Invalid target qubit. Note qubits are zero indexed.",
27 "Invalid control qubit. Note qubits are zero indexed.",
28 "Control qubit cannot equal target qubit.",
29 "Invalid number of control qubits",
30 "Invalid unitary matrix.",
31 "Invalid rotation arguments.",
32 "Invalid system size. Cannot print output for systems greater than 5 qubits.",
33 "Can't collapse to state with zero probability.",
34 "Invalid number of qubits.",
35 "Invalid measurement outcome -- must be either 0 or 1." 66 sprintf(filename,
"state_rank_%d.csv", multiQubit.
chunkId);
67 state = fopen(filename,
"w");
68 if (multiQubit.
chunkId==0) fprintf(state,
"real, imag\n");
70 for(index=0; index<multiQubit.
numAmps; index++){
81 long long int numAmps = 1L << multiQubit.
numQubits;
82 long long int numAmpsPerRank = numAmps/multiQubit.
numChunks;
85 printf(
"Number of qubits is %d.\n", multiQubit.
numQubits);
86 printf(
"Number of amps is %lld.\n", numAmps);
87 printf(
"Number of amps per rank is %lld.\n", numAmpsPerRank);
93 double mag = sqrt(pow(axis.
x,2) + pow(axis.
y,2) + pow(axis.
z,2));
94 Vector unitAxis = {axis.
x/mag, axis.
y/mag, axis.
z/mag};
97 alpha.
real = cos(angle/2.0);
98 alpha.
imag = -sin(angle/2.0)*unitAxis.
z;
99 beta.
real = sin(angle/2.0)*unitAxis.
y;
100 beta.
imag = -sin(angle/2.0)*unitAxis.
x;
106 Vector unitAxis = {1, 0, 0};
112 Vector unitAxis = {0, 1, 0};
118 Vector unitAxis = {0, 0, 1};
124 double mag = sqrt(pow(axis.
x,2) + pow(axis.
y,2) + pow(axis.
z,2));
125 Vector unitAxis = {axis.
x/mag, axis.
y/mag, axis.
z/mag};
128 alpha.
real = cos(angle/2.0);
129 alpha.
imag = -sin(angle/2.0)*unitAxis.
z;
130 beta.
real = sin(angle/2.0)*unitAxis.
y;
131 beta.
imag = -sin(angle/2.0)*unitAxis.
x;
137 Vector unitAxis = {1, 0, 0};
143 Vector unitAxis = {0, 1, 0};
149 Vector unitAxis = {0, 0, 1};
202 if ( fabs(sqrt(ux*ux + uy*uy + uz*uz) - 1) >
REAL_EPS )
return 0;
212 gettimeofday(&tv, NULL);
214 double time_in_mill =
215 (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ;
217 unsigned long int pid = getpid();
218 unsigned long int msecs = (
unsigned long int) time_in_mill;
219 char hostName[MAXHOSTNAMELEN+1];
220 gethostname(hostName,
sizeof(hostName));
221 unsigned long int hostNameInt =
hashString(hostName);
223 unsigned long int key[3];
224 key[0] = msecs; key[1] = pid; key[2] = hostNameInt;
239 unsigned long int hash = 5381;
243 hash = ((hash << 5) + hash) + c;
void phaseGate(MultiQubit multiQubit, const int targetQubit, enum phaseGateType type)
void rotateAroundAxis(MultiQubit multiQubit, const int rotQubit, REAL angle, Vector axis)
Rotate a single qubit by a given angle around a given vector on the Bloch-sphere. ...
void reportState(MultiQubit multiQubit)
Print the current state vector of probability amplitudes for a set of qubits to file.
void QuESTSeedRandom(unsigned long int *seedArray, int numSeeds)
numSeeds <= 64
const char * errorCodes[]
int validateAlphaBeta(Complex alpha, Complex beta)
void rotateX(MultiQubit multiQubit, const int rotQubit, REAL angle)
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.
void tGate(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit T gate.
unsigned long int hashString(char *str)
int numChunks
Number of chunks the state vector is broken up into – the number of MPI processes used...
void init_by_array(unsigned long init_key[], int key_length)
int validateUnitVector(REAL ux, REAL uy, REAL uz)
The QuEST library API and objects.
Internal functions used to implement the public facing API in qubits.h.
void rotateY(MultiQubit multiQubit, const int rotQubit, REAL angle)
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.
void QuESTSeedRandomDefault()
Seed the Mersenne Twister used for random number generation in the QuEST environment with an example ...
void controlledCompactUnitary(MultiQubit multiQubit, const int controlQubit, const int targetQubit, Complex alpha, Complex beta)
Apply a controlled unitary (single control, single target) parameterised by two given complex scalars...
void compactUnitary(MultiQubit multiQubit, const int rotQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
int numQubits
Number of qubits in the state.
void sGate(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit S gate.
void reportMultiQubitParams(MultiQubit multiQubit)
Report metainformation about a set of qubits: number of qubits, number of probability amplitudes...
void rotateZ(MultiQubit multiQubit, const int rotQubit, REAL angle)
Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase s...
void sigmaZ(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit sigma-Z (also known as the Z, Pauli-Z or phase-flip) gate. ...
void controlledRotateX(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.
int validateMatrixIsUnitary(ComplexMatrix2 u)
long long int numAmps
Number of probability amplitudes held in stateVec by this process In the non-MPI version, this is the total number of amplitudes.
void controlledRotateZ(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.
int chunkId
The position of the chunk of the state vector held by this process in the full state vector...
Represents a system of qubits.
void controlledRotateY(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.
void controlledRotateAroundAxis(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
Represents a 2x2 matrix of complex numbers.
Represents one complex number.
ComplexArray stateVec
Probablilty amplitudes for the multi qubit state.