Utilities

Mathematical Operations

qnetvo.partial_transpose(dm, d1, d2)[source]

Computes the partial transpose of a density matrix with respect to the second subsystem.

Parameters:
  • dm (np.array) – The density matrix to be partially transposed.

  • d1 (int) – The dimension of the first subsystem (e.g., \(2^m\) where \(m\) is the number of qubits in the first subsystem).

  • d2 (int) – The dimension of the second subsystem (e.g., \(2^n\) where \(n\) is the number of qubits in the second subsystem).

Returns:

The partially transposed density matrix.

Return type:

np.array

Raises:

ValueError – If the product of d1 and d2 does not match the size of the density matrix.

Circuit Tomography

qnetvo.state_vec_fn(circuit, num_wires)[source]

Constructs a function state_vec(*circ_args, basis_state=[0,...,0], **circ_kwargs) that returns the state vector representation of the output of circuit where the input to the circuit is specified in the computational basis by basis_state.

Parameters:
  • circuit (Function) – A quantum function.

  • num_wires (Int) – The number of wires to evaluate circuit on.

Returns:

A vector representing the pure quantum state output from circuit(*circ_args, **circ_kwargs) when the computational basis_state is provided as input.

Return type:

np.array

qnetvo.density_mat_fn(circuit, num_wires)[source]

Constructs a function that returns the density matrix of the specified circuit.

Parameters:
  • circuit (Function) – A quantum function.

  • num_wires (Int) – The number of wires to evaluate circuit on.

Returns:

A function density_mat(wires_out, *circ_args, basis_state=[0,...,0], **circ_kwargs) that returns the density matrix representing the quantum state on wires_out for the initialized basis_state where the quantum circuit is called as circuit(*circ_args, **circ_kwargs).

Return type:

np.array

qnetvo.unitary_matrix(circuit, num_wires, *circ_args, **circ_kwargs)[source]

Constructs the unitary matrix representation of a quantum circuit in the computational basis.

Parameters:
  • circuit (Function) – A quantum function.

  • num_wires (Int) – The number of wires needed by circuit.

  • circ_args (Positional Arguments) – Passthrough arguments for circuit.

  • circ_kwargs (keyword Arguments) – Passthrough keyword arguments for circuit.

Returns:

A unitary matrix representing the provided circuit.

Return type:

Numpy Array

File I/O

qnetvo.write_optimization_json(opt_dict, filename)[source]

Writes the optimization dictionary to a JSON file.

Parameters:
  • opt_dict (dict) – The dictionary returned by a network optimization.

  • filename (string) – The name of the JSON file to be written. Note that .json extension is automatically added.

Returns:

None

qnetvo.read_optimization_json(filepath)[source]

Reads data from an optimization JSON created via write_optimization_json.

Parameters:

filepath (string) – The path to the JSON file. Note this string must contain the .json extension.

Returns:

The optimization dictionary read from the file.

Return type:

dict

Data Conversions

qnetvo.mixed_base_num(n, base_digits)[source]

Converts a base-10 number n into a mixed base number with digit values described by the base_digits array.

Parameters:
  • n (int) – A base-10 number

  • base_digits (list[int]) – A list of integers representing the largest value for each digit in the mixed base number

Returns:

A list of integers representing the mixed base number.

Return type:

list[int]