Utilities#

File I/O#

qnetti.datetime_now_string()[source]#

Retrieves the current datetime in universal time coordinates (UTC).

Returns:

The current datetime formatted as YYYY-MM-DDTHH-mm-SSZ

Return type:

String

qnetti.tmp_dir(filepath)[source]#

Creates a temporary directory tmp/ in the directory specified by filepath.

Parameters:

filepath (String) – The filepath to the directory in which to create a temporary directory.

Returns:

The path to "filepath/tmp/"

Return type:

String

qnetti.mkdir(filepath, dir_name)[source]#

Creates a directory dir_name/ in the directory specified by filepath.

Parameters:
  • filepath (String) – The filepath to the directory in which to create the directory.

  • dir_name (String) – The name of the directory to create.

Returns:

The path to "filepath/dir_name/"

Return type:

String

qnetti.get_files(path, regex)[source]#

Retrieves all data files that match the regex in the directory specified by path.

Parameters:
  • path (string) – A file path to search in.

  • regex (regex) – A regular expression.

Returns:

A list of file names that match the specified regex.

Return type:

list[String]

qnetti.write_json(json_dict, filename)[source]#

Writes the dictionary to JSON file with name filename. :param json_dict: The dictionary to write as a JSON file. :type json_dict: dict :param filename: The name of the JSON file. Note that .json extension is automatically added. :type filename: string :returns: None

qnetti.read_json(filename)[source]#

Reads data from a JSON file. :param filename: The path to the JSON file. Note this string must contain the .json extension. :type filename: string :returns: The dictionary read from the JSON file. :rtype: dict

Scripting#

qnetti.infer_ibm_network_shot_dependence(provider, prep_node, ibm_device_name='ibmq_qasm_simulator', shots_list=[10, 100, 1000, 10000], meas_wires=None, prep_node_name='', num_cov_steps=0, num_vn_steps=0, num_mi_steps=0, num_mmi_steps=0, mi_step_size=0.1, mmi_step_size=0.25, cov_step_size=0.1, vn_step_size=0.1, cov_init_json={}, vn_init_json={}, mi_init_json={}, mmi_init_json={}, init_data_json={}, warm_start_step=0)[source]#

Performs network inference on an IBMQ machine over a range of shot numbers. The prepared state is specified as the prep_node and the number of shots are passed as the shots_list parameter.

The connection to the IBM hardware requires an IBMQ account. The IBM provider can be constructed using the private token as:

token = "XYZ"   # secret IBMQ API token for your account
IBMQ.save_account(token=token, hub="ibm-q", group="open", project="main", overwrite=True)

provider = IBMQ.load_account()
Parameters:
  • provide – An IBM provider (see above).

  • prep_node (qnetvo.PrepareNode) – A qNetVO PrepareNode class describing the state to infer.

Plotting#

qnetti.plot_ibm_network_inference(data_dir, shots_list, num_qubits, prep_node, ibm_device_name='ibmq_belem', sim_device_name='default.qubit', title='', cov_mat_match=[], mi_char_mat_match=[], mmi_char_mat_match=[], opt_yticks=[], avg_data=None)[source]#

Creates a plot of the data acquired from the quantum computing hardware. See Fig. 8 of our Arxiv Paper.

qnetti.plot_qubit_inference_heat_map(data_dir, device_name, title='', cov_mat_match=None, char_mat_match=None)[source]#

Creates a heatmap plot of the data acquired from the quantum computing hardware. See Fig. 9 of our Arxiv Paper