Class
Tomography
Tomography()
This is the main tomography object that the library is built around. The goal is to only have one tomography object and edit the
configuration settings as you go.
The constructor initializes the conf settings and error functions with the default values below:
self.conf = {'NQubits': 2,
'NDetectors': 1,
'Crosstalk': np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]),
'Bellstate': 0,
'DoDriftCorrection': 0,
'DoAccidentalCorrection' : 1,
'DoErrorEstimation': 0,
'Window': 0,
'Efficiency': 0,
'RhoStart': [],
'IntensityMap': [[1]],
'Beta': 0}
self.err_functions = ['concurrence','tangle','entropy','linear_entropy','negativity','purity']
Tomography.setConfSetting
Tomography.setConfSetting(setting, val)
Sets a specific self.conf setting. This is no longer needed but will be kept in the class to support old code.
-
setting : string
The setting you want to update. Possible values are ['NQubits', 'NDetectors', 'Crosstalk', 'Bellstate', 'DoDriftCorrection', 'DoAccidentalCorrection', 'DoErrorEstimation', 'Window', 'Efficiency', 'RhoStart', 'Beta']
-
val : ndarray, int, or string
The new value you want to the setting to be.
|
Tomography.importConf
Tomography.importConf(conftxt)
Import a text file containing the configuration settings.
Tomography.importData
Tomography.importData(datatxt)
Import a text file containing the tomography data and run tomography.
-
datatxt : string
path to data file
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : float
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.importEval
Tomography.importEval(evaltxt)
Import a eval file containing the tomography data and the configuration setting, then run tomography.
-
evaltxt : string
path to eval file
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : float
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.StateTomography
Tomography.StateTomography(measurements, counts)
Main function that runs tomography. This function requires a set of measurements and a set of counts.
-
measurements : ndarray shape = ( Number of measurements , 2*NQubits )
Each row in the matrix is a set of independent measurements.
-
counts : ndarray shape = (Number of measurements, NDetectors**NQubits )
Each row in the matrix is a set of independent measurements.
-
crosstalk : ndarray shape = ( Number of measurements , 2**NQubits,2**NQubits ) (optional)
The crosstalk matrix to compensate for inefficentcies in your beam splitter.
-
efficiency : 1darray with length = NQubits*NDetectors (optional)
The relative efficienies between your detector pairs.
-
time : 1darray with length = Number of measurements (optional)
The total duration of each measurment.
-
singles : ndarray shape = ( Number of measurements , 2*NQubits ) (optional)
The singles counts on each detector.
-
window : 1darray with length = NQubits*NDetectors (optional)
The coincidence window duration for each detector pair.
-
error : int (optional)
The number of monte carlo states used to estimate the properties of the state.
-
intensities : 1darray with length = Number of measurements (optional)
The relative intensity of each measurement. Used for drift correction.
-
method : ['MLE','HMLE','BME','LINER'] (optional)
Which method to use to run tomography. Default is MLE
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : The predicted overall intensity used to normalize the state.
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.StateTomography_Matrix
Tomography.StateTomography_Matrix(tomo_input, intensities)
Main function that runs tomography.
-
tomo_input : ndarray
The input data for the current tomography. Example can be seen at top of page.
-
intensities : 1darray with length = number of measurements (optional)
Relative pump power (arb. units) during measurement; used for drift correction. Default will be an array of ones
-
method : ['MLE','HMLE','BME','LINER'] (optional)
Which method to use to run tomography. Default is MLE
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : The predicted overall intensity used to normalize the state.
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.tomography_MLE
Tomography.tomography_MLE(starting_matrix, coincidences, measurements, accidentals,overall_norms)
Runs tomography using maximum likelyhood estimation.
-
starting_matrix : ndarray with shape = (2^numQubits, 2^numQubits)
The starting predicted state.
-
coincidences : ndarray shape = (Number of measurements, NDetectors**NQubits)
The counts of the tomography.
-
measurements_densities : ndarray with shape = (NDetectors*number of measurements,2^numQubits, 2^numQubits)
The measurements of the tomography in density matrix form.
-
accidentals : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The accidental values of the tomography. Used for accidental correction.
-
overall_norms : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The relative weights of each measurment. Used for drift correction.
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : float
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.tomography_HMLE
Tomography.tomography_HMLE(starting_matrix, coincidences, measurements, accidentals,overall_norms)
Runs tomography using hedged maximum likelyhood estimation.
-
starting_matrix : ndarray with shape = (2^numQubits, 2^numQubits)
The starting predicted state.
-
coincidences : ndarray shape = (Number of measurements, NDetectors**NQubits)
The counts of the tomography.
-
measurements_densities : ndarray with shape = (NDetectors*number of measurements,2^numQubits, 2^numQubits)
The measurements of the tomography in density matrix form.
-
accidentals : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The accidental values of the tomography. Used for accidental correction.
-
overall_norms : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The relative weights of each measurment. Used for drift correction.
|
-
rhog : ndarray with shape = (2^numQubits, 2^numQubits)
The predicted density matrix.
-
intensity : float
The predicted overall intensity used to normalize the state.
-
fvalp : float
Final value of the internal optimization function. Values greater than the number of measurements indicate poor agreement with a quantum state.
|
Tomography.tomography_LINEAR
Tomography.tomography_LINEAR(coincidences, measurements,overall_norms)
Uses linear techniques to find a starting state for maximum likelihood estimation.
-
coincidences : ndarray shape = (Number of measurements, NDetectors**NQubits)
The counts of the tomography.
-
measurements : ndarray with shape = (NDetectors*number of measurements,2^numQubits)
The measurements of the tomography in pure state form.
-
overall_norms : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The relative weights of each measurment. Used for drift correction.
|
Tomography.filter_data
Tomography.filter_data(tomo_input)
Filters the data into separate arrays.
-
coincidences : ndarray shape = (Number of measurements, NDetectors**NQubits)
The counts of the tomography.
-
measurements_densities : ndarray with shape = (NDetectors*number of measurements,2^numQubits, 2^numQubits)
The measurements of the tomography in density matrix form.
-
measurements_pures : ndarray with shape = (NDetectors*number of measurements, 2^numQubits)
The measurements of the tomography in pure state form.
-
acc : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The accidental values of the tomography. Used for accidental correction.
-
overall_norms : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit
The relative weights of each measurment. Used for drift correction.
|
Tomography.checkForInvalidSettings
Tomography.checkForInvalidSettings()
Description not currently available
Tomography.getCoincidences
Tomography.getCoincidences()
Returns an array of counts for all the measurements.
Tomography.getSingles
Tomography.getSingles()
Returns an array of singles for all the measurements.
Tomography.getTimes
Tomography.getTimes()
Returns an array of times for all the measurements.
Tomography.getMeasurements
Tomography.getMeasurements()
Returns an array of measurements in pure state form for all the measurements.
Tomography.getNumQubits
Tomography.getNumQubits()
returns the number of qubits for the current configurations.
Tomography.getNumCoinc
Tomography.getNumCoinc()
Returns the number of coincidences per measurement for the current configurations.
Tomography.getNumSingles
Tomography.getNumSingles()
Returns the number of singles per measurement for the current configurations.
Tomography.getNumDetPerQubit
Tomography.getNumDetPerQubit()
returns the number of detectors per qubit for the current configurations.
Tomography.getStandardBasis
Tomography.getStandardBasis(numBit,numDet = -1)
Returns an array of standard measurements in separated pure state form for the given number of qubits. It is the same format used in the tomo_input matrix.
-
numBits : int
number of qubits you want for each measurement. Default will use the number of qubits in the current configurations.
-
numDet : 1 or 2
Number of detectors for each measurement Default will use the number of qubits in the current configurations.
|
Tomography.getProperties
Tomography.getProperties(bounds)
Returns all the properties of the given density matrix.
Tomography.tomography_states_generator
Tomography.tomography_states_generator(n)
Uses monte carlo simulation to create random states similar to the estimated state. The states are also saved under self.mont_carlo_states
-
rhop : ndarray with shape = (n, 2^numQubits, 2^numQubits)
The approximate density matrices.
-
intenp : 1darray with length = n
The intensity of each approximate density matrices.
-
fvalp : 1darray with length = n
The fval of the regression associated with each approximate density matrices.
|
Tomography.getBellSettings
Tomography.getBellSettings(bounds)
Returns the optimal measurment settings for the CHSH bell inequality. In Progress, have not checked.
Tomography.printLastOutput
Tomography.printLastOutput(bounds)
Prints the properties of the last tomography to the console. Properties are defined in tomography conf settings. The calculated properties are determined by self.err_functions.
Tomography.exportToEval
Tomography.exportToEval(filePath)
Exports the input data to the specified file path. You can rerun tomography on this file using importEval() command.
Tomography.exportToConf
Tomography.exportToConf(filePath)
Exports the conf data to the specified file path. You can rerun tomography on this file using importConf() and importData() command.
Tomography.exportToData
Tomography.exportToData(filePath)
Exports the tomo_input matrix data to the specified file path. You can rerun tomography on this file using importConf() and importData() command.
log_likelyhood
log_likelyhood(t, coincidences, accidentals, m, prediction)
This is the log likelyhood function. It used in bayesian tomography.
-
t : ndarray
T values of the current predicted state.
-
coincidences : ndarray with length = number of measurements or shape = (number of measurements, 2^numQubits) for 2 det/qubit
The counts of the tomography.
-
accidentals : ndarray with length = number of measurements or shape = (number of measurements, 2^numQubits) for 2 det/qubit
The singles values of the tomography. Used for accidental correction.
-
m : ndarray with shape = (2^numQubits, 2^numQubits, number of measurements)
The measurements of the tomography in density matrix form.
-
prediction : ndarray
Predicted counts from the predicted state.
-
overall_norms : 1darray with length = number of measurements or length = number of measurements * 2^numQubits for 2 det/qubit. (optional)
The relative weights of each measurment. Used for drift correction.
|
density2tm
density2tm(rhog)
Converts a density matrix into a lower t matrix.
-
rhog : ndarray
Array to be converted.
|
density2t
density2t(rhog)
Converts a density matrix into a list of t values
-
rhog : ndarray
Array to be converted.
|
toDensity
toDensity(psiMat)
Converts a pure state into a density matrix.
t_matrix
t_matrix(t)
Converts a list of t values to an lower t matrix.
-
tm : ndarray
Lower t matrix.
|
t_to_density
t_to_density(t)
Converts a list of t values to a density matrix.
-
rhog : ndarray
Density Matrix.
|
fidelity
fidelity(state1, state2)
Calculates the fidelity between the two input states.
-
val : float
The calculated fidelity.
|
concurrence
concurrence(rhog)
Calculates the concurrence of the input state.
tangle
tangle(rhog)
Calculates the tangle of the input state.
-
rhog : ndarray
Density Matrix of the desired state. Tangle is calculated by squaring the concurrence.
-
val : float
The calculated tangle. Other Properties entropy;linear_entropy;negativity;purity;concurrence See Also ------ err_functions;getProperties
|
entropy
entropy(rhog)
Calculates the Von Neumann Entropy of the input state.
linear_entropy
linear_entropy(rhog)
Calculates the linear entropy of the input state.
-
rhog : ndarray
Density Matrix of the desired state.
-
val : float
The calculated linear entropy ranging from 0 to 1/(2^numQubits). A value of zero corresponds to a completly pure state. Other Properties entropy;concurrence;negativity;purity;tangle See Also ------ err_functions;getProperties
|
negativity
negativity(rhog)
Calculates the negativity of the input state.
purity
purity(rhog)
Calculates the purity of the input state.
-
rhog : ndarray
Density Matrix of the desired state.
-
val : float
The calculated purity ranging from 1/(2^numQubits) to 1. A value of one corresponds to a completly pure state. Other Properties entropy;linear_entropy;negativity;concurrence;tangle See Also ------ err_functions;getProperties
|
partial_transpose
partial_transpose(rhog)
Returns the partial transpose of the input density matrix. DISCLAIMER : Tests in progress
random_pure_state
random_pure_state(N)
Returns a random quantum state from a uniform distribution across the space.
random_density_state
random_density_state(N)
Returns a random quantum density from an approximate uniform distribution across the space.
random_bell_state
random_bell_state(N)
Randomly returns one of the 4 bell state. For 1 qubits on of the standard basis states is returned. For states with dimension greater then 2 the Greenberger-Horne-Zeilingerstate is returned with a random phase.
random_ginibre
random_ginibre(D)
Returns a random matrix from the Ginibre ensemble of size DxD. This is a complex matrix whos elements are a+ib | a,b iid. Norm(0,1)
-
mat : ndarray with shape = (2^N, 2^N)
The random matrix
|
densityOperation
densityOperation(D)
Performs the operation on the density matrix
ketOperation
ketOperation(D)
Performs the operation on the pure state.
quarterWavePlate
quarterWavePlate(D)
returns the quantum gate associated with a quarter wave plate.
halfWavePlate
halfWavePlate(D)
returns the quantum gate associated with a half wave plate.
getWavePlateBasis
getWavePlateBasis(theta_qwp,theta_hwp,flipPBS)
Given the angles for the QWP and HWP plate find the measurement basis. PBS is assumed to transmit Horizontally polarized light and reflect vertical. This function does not take into account crosstalk.
-
theta_qwp : string
The angle with respect to horizontal for the quarter wave plate.
-
theta_hwp : string
The angle with respect to horizontal for the quarter wave plate. flipPBS: bool Set this to true to assume the PBS transmits V and reflects H
|
removeGlobalPhase
removeGlobalPhase(D)
Factors out the global phase of the given state by dividing the entire state by the phase of the first component.
-
pure_state : 1darray with length = 2^nQubits
The state in ket form.
|
makeRhoImages
makeRhoImages(p, plt_given, customColor)
Creates matlab plots of the density matrix.
-
p : ndarray with shape = (n, 2^numQubits, 2^numQubits)
The density matrix you want to create plots of.
-
plt_given : matplotlib.pyplot
Input pyplot for which the figures will be saved on to.
-
customColor : boolean
Specify if you want our custom colorMap. Default is true See Also ------ saveRhoImages
|
saveRhoImages
saveRhoImages(p, pathToDirectory, customColor)
Creates and saves matlab plots of the density matrix.
printLastOutput
printLastOutput(tomo,bounds)
Prints the properties of the last tomography to the console. Properties are defined in tomography conf settings. The calculated properties are determined by self.err_functions.
-
tomo : Tomography
The tomography object you want to see the output of.
-
bounds : int (optional)
The number of monte carlo runs you want to perform to get a better estimate of each property. Default will use whatever is set in the conf settings.
|
matrixToHTML
matrixToHTML(M)
Creates an HTML table based on the given matrix.
propertiesToHTML
propertiesToHTML(vals)
Creates an HTML table based on the given property values.
stateToString
stateToString(vals)
Creates a string of the 1d pure state.
-
pure_state : 1darray with length = 2
The state in ket form.
|
Conf File
This file states the configurations of the tomography. The syntax of the txt file is python. You write the
conf settings just like you would set a python dictionary.
These are the following configuration settings:
- 'NQubits'
- Values : >= 1
- Desc : The number of qubits the quantum state has. It will take exponentially more time for more qubits.
- Default : 2
- 'NDetectors'
- Values : 1 or 2
- Desc : The number of detectors per qubit used during the physical tomography of the quantum state.
- Default : 1
- 'ctalk'
- Values : matrix that is (2^NQubits) by (2^NQubits)
- Desc : Cross talk Matrix of the setup.
- Default : identity matrix with appropriate size
- 'Bellstate'
- Values : 'no' or 'yes'
- Desc : Give the optimal measurement settings for a CHSH bell inequality for the estimated density matrix.
These settings are found through a numerical search over all possible measurement settings.
- Default : 'no'
- 'DoDriftCorrection'
- Values : 'no' or 'yes'
- Desc : Whether of not you want to perform drift correction on the state
- Default : 'no'
- 'DoAccidentalCorrection'
- Values : 'no' or 'yes'
- Desc : Whether of not you want to perform accidental corrections on the state.
- Default : 'no'
- 'Window'
- Values : 0 or array like, dimension = 1
- Desc : Coincidence window durations (in nanoseconds) to calculate the accidental rates. The
four windows should be entered in the order of the detector pairs 1-2, 1-4, 3-2, 3-4, where A-B
corresponds to a coincidence measurement between detector A and detector B.
- Default : '0'
- 'Efficiency'
- Values : 0 or array like, dimension = 1
- Desc : vector that lists the relative coincidence efficiencies of detector pairs when using 2 detectors per
qubit. The order is detector 1-2, 1-4, 3-2, 3-4.
- Default : 0
Example:
conf['NQubits'] = 2
conf['NDetectors'] = 1
conf['Crosstalk'] = [[0.9842,0.0049,0.0049,0],[0.0079,0.9871,0,0.0050],[0.0079,0,0.9871,0.0050],[0.001,0.0079,0.0079,0.9901]]
conf['UseDerivative'] = 0
conf['Bellstate'] = 1
conf['DoErrorEstimation'] = 3
conf['DoDriftCorrection'] = 'no'
conf['Window'] = 0
conf['Efficiency'] = [0.9998,1.0146,0.9195,0.9265]
Data File
This file states the data of the measurements.Both tomo_input the intensity must be specified. The syntax of the txt file is python. You write the
data settings just like you would set a python matrix.
This is the following layout of the tomo_input matrix:
-
tomo_input
- Values : 2d numpy array
- Desc : Relative pump power (arb. units) during measurement; used for drift correction.
For n detectors:
- tomo_input[ :, 0 ]: times
- tomo_input[ :, 1 : n_qubit + 1) ]: singles
- tomo_input[ :, n_qubit + 1 ]: coincidences
- tomo_input[ :, n_qubit + 2 : 3 * n_qubit + 2) ]: measurements
For 2n detectors:
- tomo_input[ :, 0 ]: times
- tomo_input[ :, 1 : 2 * n_qubit + 1 ]: singles
- tomo_input[ :, 2 * n_qubit + 1 : 2 ** n_qubit + 2 * n_qubit + 1 ]: coincidences
- tomo_input[ :, 2 ** n_qubit + 2 * n_qubit + 1 : 2 ** n_qubit + 4 * n_qubit + 1 ]: measurements
- intensity
- Values : 1d numpy array
- Desc : Relative pump power (arb. units) during measurement; used for drift correction.
Example:
This example is for 2 qubits using 1 detector.
tomo_input = np.array(
[[1,0,0,3708,1,0,1,0],
[1,0,0,77,1,0,0,1],
[1,0,0,1791,1,0,0.7071,0.7071],
[1,0,0,2048,1,0,0.7071,0.7071j],
[1,0,0,51,0,1,1,0],
[1,0,0,3642,0,1,0,1],
[1,0,0,2096,0,1,0.7071,0.7071],
[1,0,0,1926,0,1,0.7071,0.7071j],
[1,0,0,1766,0.7071,0.7071,1,0],
[1,0,0,1914,0.7071,0.7071,0,1],
[1,0,0,1713,0.7071,0.7071,0.7071,0.7071],
[1,0,0,3729,0.7071,0.7071,0.7071,0.7071j],
[1,0,0,2017,0.7071,0.7071j,1,0],
[1,0,0,1709,0.7071,0.7071j,0,1],
[1,0,0,3686,0.7071,0.7071j,0.7071,0.7071],
[1,0,0,2404,0.7071,0.7071j,0.7071,0.7071j]])
intensity = np.array([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])
Eval File
This text file contains all the information for a tomography. It is essentially a conf file and a data file combined into one file.
Example:
This example is for 2 qubits using 1 detector.
conf['NQubits'] = 2
conf['NDetectors'] = 1
conf['Crosstalk'] = [[0.9842,0.0049,0.0049,0],[0.0079,0.9871,0,0.0050],[0.0079,0,0.9871,0.0050],[0.001,0.0079,0.0079,0.9901]]
conf['UseDerivative'] = 0
conf['Bellstate'] = 1
conf['DoErrorEstimation'] = 3
conf['DoDriftCorrection'] = 'no'
conf['Window'] = 0
conf['Efficiency'] = [0.9998,1.0146,0.9195,0.9265]
tomo_input = np.array(
[[1,0,0,3708,1,0,1,0],
[1,0,0,77,1,0,0,1],
[1,0,0,1791,1,0,0.7071,0.7071],
[1,0,0,2048,1,0,0.7071,0.7071j],
[1,0,0,51,0,1,1,0],
[1,0,0,3642,0,1,0,1],
[1,0,0,2096,0,1,0.7071,0.7071],
[1,0,0,1926,0,1,0.7071,0.7071j],
[1,0,0,1766,0.7071,0.7071,1,0],
[1,0,0,1914,0.7071,0.7071,0,1],
[1,0,0,1713,0.7071,0.7071,0.7071,0.7071],
[1,0,0,3729,0.7071,0.7071,0.7071,0.7071j],
[1,0,0,2017,0.7071,0.7071j,1,0],
[1,0,0,1709,0.7071,0.7071j,0,1],
[1,0,0,3686,0.7071,0.7071j,0.7071,0.7071],
[1,0,0,2404,0.7071,0.7071j,0.7071,0.7071j]])
intensity = np.array([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])
Contact
In case you have any further questions about the Python code, you should direct them
to Scott Turro or Joey Shallat.