post_processing.logparser

Implements JSON pasers, summarizing the raw QPU output files.

USAGE:
python -m post_processing.logparser summarize_dwave ./run_logs/dwave ./run_logs/summaries/dwave_summary.csv ./run_logs/summaries/dwave_stats.csv dwave

python -m post_processing.logparser summarize_ibm ./run_logs/ibm-qpu ./run_logs/summaries/ibm-qpu_summary.csv ./run_logs/summaries/ibm-qpu_stats.csv “IBM-QPU”

python -m post_processing.logparser summarize_quera ./run_logs/quera ./run_logs/summaries/quera_summary.csv ./run_logs/summaries/quera_stats.csv

python -m post_processing.logparser extract_samples dwave ./run_logs/dwave/<instance>.json ./run_logs/dwave/samples-csv/<instance>.sample.csv ./instances/QUBO ./instances/orig

The module implements the abstract parser class befining a universal interface post_processing.logparser.QPULogParser and the three derived classes for device-specific code. Each of these most notably implements the method extract_samples used to extract the data regarding individual QPU shots, which allows to recover a solution and is then used to calculate the objective values with the helper functions calculate_QUBO_objective() and calculate_orig_objective().

When run from the command line as presented above, the function specified in the first argument is run. Therefore, log parser interface is wrapped into several functions accessible from the command line.

Functions

calculate_QUBO_objective(inst_id, top_samples)

Helper: Returns the QUBO objective and the feasibility flag from a collection of samples.

calculate_orig_objective(inst_id, top_samples)

Helper: Calculates the objective given the instance ID and the collection of bitstrings.

extract_all_samples(logtype, jsondir, outdir)

Extracts the last sample from the JSONs in jsondir.

extract_samples(logtype, infile, outfile[, ...])

Extracts the last sample from the JSON log.

get_inst_type(inst_id)

Helper: Extracts the instance type from inst_id.

summarize_dwave(directory, outfile, statsfile)

Processes all the DWave logs in the given directory.

summarize_ibm(directory, outfile, statsfile)

Processes all the IBM logs in the given directory.

summarize_quera(directory, outfile, statsfile)

Processes all the QuEra logs in the given directory.

Classes

DWaveLogParser([files, log])

Implements the D-Wave specific log parsing code.

IBMLogParser([files, log, logtype])

Implements the IBM specific log parsing code.

QPULogParser([files, log, orig_dir, qubo_dir])

Implements the basic JSON log parser interface.

QuEraLogParser([files, log])

Implements the QuEra specific log parsing code.

post_processing.logparser.get_inst_type(inst_id)[source]

Helper: Extracts the instance type from inst_id.

post_processing.logparser.calculate_QUBO_objective(inst_id, top_samples, orig_dir='./instances/orig', qubo_dir='./instances/QUBO')[source]

Helper: Returns the QUBO objective and the feasibility flag from a collection of samples.

Calculates the objective values using the QUBO machinery and assesses the feasibility of each respective solution.

Parameters:
  • inst_id (str) – instance id,

  • top_samples (list) – best samples to choose from (list of bitstrings).

  • orig_dir (str) – directory with original instance JSONs,

  • qubo_dir (str) – directory with QUBO instance JSONs,

Returns:

A tuple of (obj, feas), where obj is the best (minimum) feasible QUBO objective value (just minimum if no feasible solutions found among top_samples) and feas = True if it is feasible, and False otherwise.

Notes

  • top_samples must contain a list of bitstrings, where higher

    ranking qubits are on the left: e.g., [b3, b2, b1, b0].

post_processing.logparser.calculate_orig_objective(inst_id, top_samples, orig_dir='./instances/orig')[source]

Helper: Calculates the objective given the instance ID and the collection of bitstrings.

Uses the logic of the original problem, not the universal QUBO code.

Parameters:
  • inst_id (str) – instance id,

  • top_samples (list) – best samples to choose from (bitstrings).

Notes

  • top_samples must contain a list of bitstrings, where higher

    ranking qubits are on the left: e.g., [b3, b2, b1, b0].

class post_processing.logparser.QPULogParser(files=None, log=True, orig_dir='./instances/orig', qubo_dir='./instances/QUBO')[source]

Implements the basic JSON log parser interface.

files

list of processed files (filenames)

Type:

list

df

the data accumulated

Type:

pd.DataFrame

abstract _extract_successful_line(js, filename)[source]

Extracts a single successful instance run (from a single JSON).

abstract _extract_failed_line(js, filename, statsfile=None)[source]

Extracts a single failed instance run (from a single JSON).

save(outfile, statsfile=None)[source]

Helper: saves the statistics on the processed files.

This generates *_stats.csv type of files, which summarize the number of successful and failed runs per instance.

process_files(filenames=None, outfile=None, statsfile=None)[source]

Processes the list of JSON raw log files (in filenames).

A universal high-level procedure, which relies on _extract_successful_line and _extract_failed_line methods implemented for each respective log file type (device type).

class post_processing.logparser.DWaveLogParser(files=None, log=True)[source]

Implements the D-Wave specific log parsing code.

_extract_successful_line(js, filename)[source]

Extracts a summary for a single DWave’s log.

This function extracts a “successful” summary line: the one corresponding to an experiment that yielded some solutions (feasible or not).

_extract_failed_line(js, filename)[source]

Extracts a summary for a single D-Wave’s log.

This function extracts a “failed” summary line: the one corresponding to an experiment that yielded no solutions. (A separate function is needed as some fields might be absent from such logfile, as compared to a “successful” one.)

static extract_samples(js, logfile=None, qubo_dir='./instances/QUBO', orig_dir='./instances/orig')[source]

Extracts the sample data from JSON (DWave).

Parameters:
  • js – loaded JSON,

  • logfile – log file name (to save into the output)

  • qubo_dir (str) – respective JSON files directories (for objective calculations)

  • orig_dir (str) – respective JSON files directories (for objective calculations)

Notes

  • resulting solution bitstrings are in reverse order: e.g., [b3, b2, b1, b0].

Returns:

a pd.DataFrame with the samples, or None if corresponding JSON files are not found in either of qubo_dir or orig_dir.

class post_processing.logparser.IBMLogParser(files=None, log=True, logtype='IBM')[source]

Implements the IBM specific log parsing code.

_extract_successful_line(js, filename)[source]

Extracts a single instance run, parsing a single IBM’s log.

This function extract a “successful” line: the one corresponding to an experiment that yielded some solutions (feasible or not).

_extract_failed_line(js, filename)[source]

Extracts a single instance run, parsing a single IBM log.

This function extract a “failed” summary line: the one corresponding to an experiment that yielded no solutions. (A separate function is needed as some fields might be absent from such logfile, as compared to a “successful” one.)

static extract_samples(js, logfile=None, qubo_dir='./instances/QUBO', orig_dir='./instances/orig')[source]

Extracts the sample data from JSON (IBM).

Parameters:
  • js – loaded JSON,

  • logfile (str) – log file name (to save into the output)

  • logfile – analyzed logfile name,

  • qubo_dir (str) – respective JSON files directories (for objective calculations)

  • orig_dir (str) – respective JSON files directories (for objective calculations)

Returns:

a pd.DataFrame with the samples.

static extract_convergence_data(js, logfile=None)[source]

Extracts the outer loop convergence data from an IBM log.

Parameters:
  • js – loaded JSON,

  • logfile – log file name (to save into the output)

Returns:

a pd.DataFrame with the samples.

class post_processing.logparser.QuEraLogParser(files=None, log=True)[source]

Implements the QuEra specific log parsing code.

_extract_successful_line(js, filename)[source]

Extracts a single instance run, parsing a single QuEra log.

_extract_failed_line(js, filename)[source]

This function is not implemented, we never received such result.

static extract_samples(js, logfile=None, qubo_dir='./instances/QUBO/', orig_dir='./instances/orig/')[source]

Extracts the sample data from JSON (QuEra logfile).

Parameters:
  • js – loaded JSON,

  • logfile – log file name (to save into the output)

  • qubo_dir (str) – respective JSON files directories (for objective calculations)

  • orig_dir (str) – respective JSON files directories (for objective calculations)

Note

The method assumes (UD)MIS instances only!

Returns:

a pd.DataFrame with the samples.

post_processing.logparser.summarize_dwave(directory, outfile, statsfile)[source]

Processes all the DWave logs in the given directory.

post_processing.logparser.summarize_ibm(directory, outfile, statsfile, logtype='IBM')[source]

Processes all the IBM logs in the given directory.

post_processing.logparser.summarize_quera(directory, outfile, statsfile)[source]

Processes all the QuEra logs in the given directory.

post_processing.logparser.extract_samples(logtype, infile, outfile, qubo_dir='./instances/QUBO', orig_dir='./instances/orig')[source]

Extracts the last sample from the JSON log.

post_processing.logparser.extract_all_samples(logtype, jsondir, outdir)[source]

Extracts the last sample from the JSONs in jsondir.