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 dwavepython -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.csvpython -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
|
Helper: Returns the QUBO objective and the feasibility flag from a collection of samples. |
|
Helper: Calculates the objective given the instance ID and the collection of bitstrings. |
|
Extracts the last sample from the JSONs in jsondir. |
|
Extracts the last sample from the JSON log. |
|
Helper: Extracts the instance type from |
|
Processes all the DWave logs in the given directory. |
|
Processes all the IBM logs in the given directory. |
|
Processes all the QuEra logs in the given directory. |
Classes
|
Implements the D-Wave specific log parsing code. |
|
Implements the IBM specific log parsing code. |
|
Implements the basic JSON log parser interface. |
|
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)
, whereobj
is the best (minimum) feasible QUBO objective value (just minimum if no feasible solutions found amongtop_samples
) andfeas
=True
if it is feasible, andFalse
otherwise.
Notes
top_samples
must contain a list of bitstrings, where higherranking 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 higherranking 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).
- 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, orNone
if corresponding JSON files are not found in either ofqubo_dir
ororig_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.
- 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.