module documentation

Undocumented

Function avg_photon_num Returns average photon number of state for each qumode within the circuit using the number operator.
Function counts_to_fockcounts Convert counts dictionary from Fock-basis binary representation into base-10 Fock basis (qubit measurements are left unchanged). Accepts the object returned by jobs.result(), along with the entire circuit.
Function cv_ancilla_fock_measure Simulate a circuit with an appended binary search for boson number, and determine the Fock state of a set of qumodes using phase kickback on the qubit. For more information, see Curtis et al., PRA (2021) and Wang et al...
Function cv_partial_trace Return reduced density matrix over the given Qiskit Qubits.
Function flatten Undocumented
Function fockmap Generates matrix corresponding to some specified mapping of Fock states for a single qumode. First feed function empty matrix, then call fmap_matrix however many times needed to fully define intended mapping...
Function get_probabilities Calculate the probabilities for each of the result's counts.
Function measure_all_xyz Use QuantumCircuit.measure_all() to measure all qubits in the X, Y, and Z basis.
Function qumode_avg_photon_num Returns average photon number of an individual qumode's state using the number operator.
Function simulate Convenience function to simulate using the given backend.
Function stateread Print values for states of qubits and qumodes using the result of a simulation of the statevector, e.g. using stateop, _, _, _ = c2qa.util.simulate(circuit).
Function trace_out_qubits Return reduced density matrix of the cavities by tracing out the all qubits of the CVCircuit from the given Fock state vector.
Function trace_out_qumodes Return reduced density matrix of the qubits by tracing out the cavities of the CVCircuit from the given Fock state vector.
Function _final_measurement_mapping Return the measurement mapping for the circuit.
Function _final_qumode_mapping Return the classical bits that active qumode qubits are mapped onto. Bits corresponding to distinct qumodes are grouped together
Function _find_cavity_indices Return the indices of the cavities from the circuit
Function _find_qubit_indices Return the indices of the qubits from the circuit that are not in a QumodeRegister
def avg_photon_num(circuit: CVCircuit, state, decimals: int = 2): (source)

Returns average photon number of state for each qumode within the circuit using the number operator.

Parameters
circuit:CVCircuitCircuit definine qumodes present in given state
state:Statevector or DensityMatrixfull state to operate on
decimals:intDetermines precision of calculation
Returns
floatAverage photon number to specified precision
def counts_to_fockcounts(circuit: CVCircuit, result: qiskit.result.result.Result, counts: dict = None): (source)

Convert counts dictionary from Fock-basis binary representation into base-10 Fock basis (qubit measurements are left unchanged). Accepts the object returned by jobs.result(), along with the entire circuit.

Parameters
circuit:CVCircuitCVCircuit
result:qiskit.result.result.Resultdict() of results, as returned by job.result(), for a circuit which used cv_measure()
counts:dictUndocumented
Returns
A new counts dict() which lists measurement results for the qubits and qumodes in circuit in little endian order, with Fock-basis qumode measurements reported as a base-10 integer.
def cv_ancilla_fock_measure(circuit, list_qumodes_to_sample: list, qmr_number: int = 0): (source)

Simulate a circuit with an appended binary search for boson number, and determine the Fock state of a set of qumodes using phase kickback on the qubit. For more information, see Curtis et al., PRA (2021) and Wang et al., PRX (2020).

Returns the Fock state of the qumodes in list_qumodes_to_sample, in qumode register qmr_number.

def cv_partial_trace(circuit: CVCircuit, state_vector, qubits: list): (source)

Return reduced density matrix over the given Qiskit Qubits.

First find the indices of the given Qubits, then call qiskit.quantum_info.partial_trace

Parameters
circuit:CVCircuitcircuit with results to trace (to find Qubit index)
state_vector:Statevector or DensityMatrixsimulation results to trace over
qubits:listlist of Qiskit Qubit to trace over
Returns
DensityMatrixpartial trace
def flatten(l): (source)

Undocumented

def fockmap(matrix, fock_input, fock_output, amplitude=[]): (source)

Generates matrix corresponding to some specified mapping of Fock states for a single qumode. First feed function empty matrix, then call fmap_matrix however many times needed to fully define intended mapping. Maps ith element in fock_input to ith element in fock_output with amplitude specified by ith element in amplitude. If amplitude is left blank, function assumes amp = 1 for all mappings.

Two use cases 1) int + list datatype combination (length of amp list must match length of either fock_input or fock_output, whichever is longer): >fockmap(matrix, 1, [0, 1]) ->> |0><1| + |1><1|

>fockmap(matrix, [3, 2], 0, [0.5j, 1]) ->> 0.5j|0><3| + |0><2|

2) list datatype >fockmap(matrix, [3, 2], [2, 1], [0.1j, 0.8]) ->> 0.1j|2><3| + 0.8|1><2|

>fockmap(matrix, [1, 1], [2, 4]) ->> |2><1| + |4><1|

Parameters
matrix:nested list/np.arrayMatrix that you want to change
fock_input:int/listInput state(s) for mapping, corresponds to bra
fock_output:int/listOutput states(s) for mapping, corresponds to ket
amplitude:int/float/complex/list/ndarrayAmplitudes corresponding to final mapped states
Returns
np.arrayEdited matrix
def get_probabilities(result: qiskit.result.Result): (source)

Calculate the probabilities for each of the result's counts.

Parameters
result:qiskit.result.ResultQisKit result to calculate probabilities from
Returns
dictprobablity dictionary of each state
def measure_all_xyz(circuit: qiskit.QuantumCircuit): (source)

Use QuantumCircuit.measure_all() to measure all qubits in the X, Y, and Z basis.

Returns state, result, fockcounts tuples each for the X, Y, and Z basis.

Parameters
circuit:qiskit.QuantumCircuitcircuit to measure qubits one
Returns
x, y, z state & result tuples(state, result, fockcounts) tuples for each x,y,z measurements
def qumode_avg_photon_num(state, decimals: int = 2): (source)

Returns average photon number of an individual qumode's state using the number operator.

Parameters
state:Statevector or DensityMatrixState to operate on for an individual qumode
decimals:intDetermines precision of calculation
Returns
floatAverage photon number to specified precision
def simulate(cvcircuit: CVCircuit, shots: int = 1024, return_fockcounts: bool = True, add_save_statevector: bool = True, conditional_state_vector: bool = False, per_shot_state_vector: bool = False, noise_model=None, noise_passes=None, max_parallel_threads: int = 0, discretize: bool = False): (source)

Convenience function to simulate using the given backend.

Handles calling into QisKit to simulate circuit using defined simulator.

Parameters
cvcircuit:CVCircuitUndocumented
shots:int, optionalNumber of simulation shots. Defaults to 1024.
return_fockcounts:bool, optionalSet to True if measurement results should be returned. Defaults to False
add_save_statevector:bool, optionalSet to True if a state_vector instruction should be added to the end of the circuit. Defaults to True.
conditional_state_vector:bool, optionalSet to True if the saved state vector should be contional (each state value gets its own state vector). Defaults to False.
per_shot_state_vector:bool, optionalSet to Ture if the simulation should return a separate state vector for every simulation shot.
noise_model:NoiseModel, optionalCustom noise model to pass into AerSimulator to use on each simulation shot
noise_passes:list of LocalNoisePass, optionalCustom noise pass to apply on each gate.
max_parallel_threads:int, opationalSets the maximum number of CPU cores used by OpenMP for parallelization. If set to 0 the maximum will be set to the number of CPU cores (Default: 0).
discretize:bool, optionalSet to True if circuit should be discretized to apply noise passes. Defaults to False.
circuit:CVCircuitcircuit to simulate
Returns
tuple(state, result, fock_counts) tuple from [optionally discretized] simulations
def stateread(stateop, numberofqubits, numberofmodes, cutoff, verbose=True, little_endian=False): (source)

Print values for states of qubits and qumodes using the result of a simulation of the statevector, e.g. using stateop, _, _, _ = c2qa.util.simulate(circuit).

Returns the states of the qubits and the Fock states of the qumodes with respective amplitudes.

def trace_out_qubits(circuit: CVCircuit, state_vector): (source)

Return reduced density matrix of the cavities by tracing out the all qubits of the CVCircuit from the given Fock state vector.

Parameters
circuit:CVCircuitcircuit with results to trace (to find Qubit index)
state_vector:Statevector or DensityMatrixsimulation results to trace over
Returns
DensityMatrixpartial trace
def trace_out_qumodes(circuit: CVCircuit, state_vector): (source)

Return reduced density matrix of the qubits by tracing out the cavities of the CVCircuit from the given Fock state vector.

Parameters
circuit:CVCircuitcircuit yielding the results to trace over
state_vector:Statevectorsimulation results to trace over
Returns
DensityMatrixdensity matrix of the qubits from a partial trace over the cavities
def _final_measurement_mapping(circuit): (source)

Return the measurement mapping for the circuit.

Dict keys label classical bits, whereas the values indicate the physical qubits that are measured to produce those bit values.

Parameters
circuit:QuantumCircuitInput Qiskit QuantumCircuit.
Returns
dictMapping of classical bits to qubits for final measurements.
def _final_qumode_mapping(circuit): (source)

Return the classical bits that active qumode qubits are mapped onto. Bits corresponding to distinct qumodes are grouped together

def _find_cavity_indices(circuit: CVCircuit): (source)

Return the indices of the cavities from the circuit

I.e., the indices to the qubits representing the bosonic modes.

def _find_qubit_indices(circuit: CVCircuit): (source)

Return the indices of the qubits from the circuit that are not in a QumodeRegister

I.e., the indices to the qubits themselves, not the qubits representing the bosonic modes.