c3.qiskit.c3_backend

Module Contents

class c3.qiskit.c3_backend.C3QasmSimulator(configuration, provider=None, **fields)[source]

Bases: qiskit.providers.BackendV1, abc.ABC

Inheritance diagram of c3.qiskit.c3_backend.C3QasmSimulator

An Abtract Base Class for C3 Qasm Simulators for Qiskit. This class CAN NOT be instantiated directly. Classes derived from this must compulsorily implement

def __init__(self, configuration=None, provider=None, **fields):

def _default_options(cls) -> None:

def run_experiment(self, experiment: QasmQobjExperiment) -> Dict[str, Any]:
Parameters
  • Backend (qiskit.providers.BackendV1) – The C3QasmSimulator is derived from BackendV1

  • ABC (abc.ABC) – Helper class for defining Abstract classes using ABCMeta

set_device_config(config_file: str) None[source]

Set the path to the config for the device

Parameters

config_file (str) – path to hjson file storing the configuration for all device parameters for simulation

set_c3_experiment(exp: c3.experiment.Experiment) None[source]

Set user-provided c3 experiment object for backend

Parameters

exp (Experiment) – C3 experiment object

get_labels(format: str = 'qiskit') List[str][source]

Return state labels for the system

Parameters

format (str, optional) – How to format the state labels, by default “qiskit”

Returns

A list of state labels in hex if qiskit format and decimal if c3 format

labels = ['0x1', ...]

labels = ['(0, 0)', '(0, 1)', '(0, 2)', ...]

Return type

List[str]

Raises

C3QiskitError – When an supported format is passed

disable_flip_labels() None[source]

Disable flipping of labels State Labels are flipped before returning results to match Qiskit style qubit indexing convention This function allows disabling of the flip

locate_measurements(instructions_list: List[Dict]) List[int][source]

Locate the indices of measurement operations in circuit

Parameters

instructions_list (List[Dict]) – Instructions List in Qasm style

Returns

The indices where measurement operations occur

Return type

List[int]

sanitize_instructions(instructions: qiskit.circuit.Instruction) Tuple[List[Any], List[Any]][source]

Convert from qiskit instruction object and Sanitize instructions by removing unsupported operations

Parameters

instructions (Instruction) – qasm as Qiskit Instruction object

Returns

Sanitized instruction list

Qasm style list of instruction represented as dicts

Return type

Tuple[List[Any], List[Any]]

Raises

UserWarning – Warns user about unsupported operations in circuit

generate_shot_readout()[source]

Generate shot style readout from population

Returns

List of shots for each output state

Return type

List[int]

run(qobj: C3QasmSimulator.run.qobj, **backend_options) c3.qiskit.c3_job.C3Job[source]

Parse and run a Qobj

Parameters
  • qobj (Qobj) – The Qobj payload for the experiment

  • backend_options (dict) – backend options

Returns

An instance of the C3Job (derived from JobV1) with the result

Return type

C3Job

Raises

QiskitError – Support for Pulse Jobs is not implemented

Notes

backend_options: Is a dict of options for the backend. It may contain:

"initial_statevector": vector_like

The initial_statevector option specifies a custom initial statevector for the simulator to be used instead of the all zero state. This size of this vector must be correct for the number of qubits in all experiments in the qobj. Example:

backend_options = {
    "initial_statevector": np.array([1, 0, 0, 1j]) / np.sqrt(2),
}
"params": list

List of parameter values. Can be nested, if a parameter is matrix valued.

"opt_map": list

Corresponding identifiers for the parameter values.

"shots": int

Total number of measurement shots.

"memory": bool

Whether individual measurement readout is stored.

set_options(**fields)

Set the options fields for the backend

This method is used to update the options of a backend. If you need to change any of the options prior to running just pass in the kwarg with the new value for the options.

Parameters

fields – The fields to update the options

Raises

AttributeError – If the field passed in is not part of the options

configuration()

Return the backend configuration.

Returns

the configuration for the backend.

Return type

BackendConfiguration

properties()

Return the backend properties.

Returns

the configuration for the backend. If the backend does not support properties, it returns None.

Return type

BackendProperties

provider()

Return the backend Provider.

Returns

the Provider responsible for the backend.

Return type

Provider

status()

Return the backend status.

Returns

the status of the backend.

Return type

BackendStatus

name()

Return the backend name.

Returns

the name of the backend.

Return type

str

__str__()

Return str(self).

__repr__()

Official string representation of a Backend.

Note that, by Qiskit convention, it is consciously not a fully valid Python expression. Subclasses should provide ‘a string of the form <…some useful description…>’. [0]

[0] https://docs.python.org/3/reference/datamodel.html#object.__repr__

property options

Return the options for the backend

The options of a backend are the dynamic parameters defining how the backend is used. These are used to control the run() method.

class c3.qiskit.c3_backend.C3QasmPerfectSimulator(configuration=None, provider=None, **fields)[source]

Bases: C3QasmSimulator

Inheritance diagram of c3.qiskit.c3_backend.C3QasmPerfectSimulator

A C3-based perfect gates simulator for Qiskit

Parameters

C3QasmSimulator (c3.qiskit.c3_backend.C3QasmSimulator) – Inherits the C3QasmSimulator and implements a perfect gate simulator

set_device_config(config_file: str) None

Set the path to the config for the device

Parameters

config_file (str) – path to hjson file storing the configuration for all device parameters for simulation

set_c3_experiment(exp: c3.experiment.Experiment) None

Set user-provided c3 experiment object for backend

Parameters

exp (Experiment) – C3 experiment object

get_labels(format: str = 'qiskit') List[str]

Return state labels for the system

Parameters

format (str, optional) – How to format the state labels, by default “qiskit”

Returns

A list of state labels in hex if qiskit format and decimal if c3 format

labels = ['0x1', ...]

labels = ['(0, 0)', '(0, 1)', '(0, 2)', ...]

Return type

List[str]

Raises

C3QiskitError – When an supported format is passed

disable_flip_labels() None

Disable flipping of labels State Labels are flipped before returning results to match Qiskit style qubit indexing convention This function allows disabling of the flip

locate_measurements(instructions_list: List[Dict]) List[int]

Locate the indices of measurement operations in circuit

Parameters

instructions_list (List[Dict]) – Instructions List in Qasm style

Returns

The indices where measurement operations occur

Return type

List[int]

sanitize_instructions(instructions: qiskit.circuit.Instruction) Tuple[List[Any], List[Any]]

Convert from qiskit instruction object and Sanitize instructions by removing unsupported operations

Parameters

instructions (Instruction) – qasm as Qiskit Instruction object

Returns

Sanitized instruction list

Qasm style list of instruction represented as dicts

Return type

Tuple[List[Any], List[Any]]

Raises

UserWarning – Warns user about unsupported operations in circuit

generate_shot_readout()

Generate shot style readout from population

Returns

List of shots for each output state

Return type

List[int]

run(qobj: C3QasmSimulator.run.qobj, **backend_options) c3.qiskit.c3_job.C3Job

Parse and run a Qobj

Parameters
  • qobj (Qobj) – The Qobj payload for the experiment

  • backend_options (dict) – backend options

Returns

An instance of the C3Job (derived from JobV1) with the result

Return type

C3Job

Raises

QiskitError – Support for Pulse Jobs is not implemented

Notes

backend_options: Is a dict of options for the backend. It may contain:

"initial_statevector": vector_like

The initial_statevector option specifies a custom initial statevector for the simulator to be used instead of the all zero state. This size of this vector must be correct for the number of qubits in all experiments in the qobj. Example:

backend_options = {
    "initial_statevector": np.array([1, 0, 0, 1j]) / np.sqrt(2),
}
"params": list

List of parameter values. Can be nested, if a parameter is matrix valued.

"opt_map": list

Corresponding identifiers for the parameter values.

"shots": int

Total number of measurement shots.

"memory": bool

Whether individual measurement readout is stored.

set_options(**fields)

Set the options fields for the backend

This method is used to update the options of a backend. If you need to change any of the options prior to running just pass in the kwarg with the new value for the options.

Parameters

fields – The fields to update the options

Raises

AttributeError – If the field passed in is not part of the options

configuration()

Return the backend configuration.

Returns

the configuration for the backend.

Return type

BackendConfiguration

properties()

Return the backend properties.

Returns

the configuration for the backend. If the backend does not support properties, it returns None.

Return type

BackendProperties

provider()

Return the backend Provider.

Returns

the Provider responsible for the backend.

Return type

Provider

status()

Return the backend status.

Returns

the status of the backend.

Return type

BackendStatus

name()

Return the backend name.

Returns

the name of the backend.

Return type

str

__str__()

Return str(self).

__repr__()

Official string representation of a Backend.

Note that, by Qiskit convention, it is consciously not a fully valid Python expression. Subclasses should provide ‘a string of the form <…some useful description…>’. [0]

[0] https://docs.python.org/3/reference/datamodel.html#object.__repr__

property options

Return the options for the backend

The options of a backend are the dynamic parameters defining how the backend is used. These are used to control the run() method.

class c3.qiskit.c3_backend.C3QasmPhysicsSimulator(configuration=None, provider=None, **fields)[source]

Bases: C3QasmSimulator

Inheritance diagram of c3.qiskit.c3_backend.C3QasmPhysicsSimulator

A C3-based perfect gates simulator for Qiskit

Parameters

C3QasmSimulator (c3.qiskit.c3_backend.C3QasmSimulator) – Inherits the C3QasmSimulator and implements a physics based simulator

run_experiment(experiment: qiskit.qobj.qasm_qobj.QasmQobjExperiment) Dict[str, Any][source]

Run an experiment (circuit) and return a single experiment result

Parameters

experiment (QasmQobjExperiment) – experiment from qobj experiments list

Returns

A result dictionary which looks something like:

{
"name": name of this experiment (obtained from qobj.experiment header)
"seed": random seed used for simulation
"shots": number of shots used in the simulation
"data":
    {
    "counts": {'0x9: 5, ...},
    "memory": ['0x9', '0xF', '0x1D', ..., '0x9']
    },
"status": status string for the simulation
"success": boolean
"time_taken": simulation time of this single experiment
}

Return type

Dict[str, Any]

Raises

C3QiskitError – If an error occured

set_device_config(config_file: str) None

Set the path to the config for the device

Parameters

config_file (str) – path to hjson file storing the configuration for all device parameters for simulation

set_c3_experiment(exp: c3.experiment.Experiment) None

Set user-provided c3 experiment object for backend

Parameters

exp (Experiment) – C3 experiment object

get_labels(format: str = 'qiskit') List[str]

Return state labels for the system

Parameters

format (str, optional) – How to format the state labels, by default “qiskit”

Returns

A list of state labels in hex if qiskit format and decimal if c3 format

labels = ['0x1', ...]

labels = ['(0, 0)', '(0, 1)', '(0, 2)', ...]

Return type

List[str]

Raises

C3QiskitError – When an supported format is passed

disable_flip_labels() None

Disable flipping of labels State Labels are flipped before returning results to match Qiskit style qubit indexing convention This function allows disabling of the flip

locate_measurements(instructions_list: List[Dict]) List[int]

Locate the indices of measurement operations in circuit

Parameters

instructions_list (List[Dict]) – Instructions List in Qasm style

Returns

The indices where measurement operations occur

Return type

List[int]

sanitize_instructions(instructions: qiskit.circuit.Instruction) Tuple[List[Any], List[Any]]

Convert from qiskit instruction object and Sanitize instructions by removing unsupported operations

Parameters

instructions (Instruction) – qasm as Qiskit Instruction object

Returns

Sanitized instruction list

Qasm style list of instruction represented as dicts

Return type

Tuple[List[Any], List[Any]]

Raises

UserWarning – Warns user about unsupported operations in circuit

generate_shot_readout()

Generate shot style readout from population

Returns

List of shots for each output state

Return type

List[int]

run(qobj: C3QasmSimulator.run.qobj, **backend_options) c3.qiskit.c3_job.C3Job

Parse and run a Qobj

Parameters
  • qobj (Qobj) – The Qobj payload for the experiment

  • backend_options (dict) – backend options

Returns

An instance of the C3Job (derived from JobV1) with the result

Return type

C3Job

Raises

QiskitError – Support for Pulse Jobs is not implemented

Notes

backend_options: Is a dict of options for the backend. It may contain:

"initial_statevector": vector_like

The initial_statevector option specifies a custom initial statevector for the simulator to be used instead of the all zero state. This size of this vector must be correct for the number of qubits in all experiments in the qobj. Example:

backend_options = {
    "initial_statevector": np.array([1, 0, 0, 1j]) / np.sqrt(2),
}
"params": list

List of parameter values. Can be nested, if a parameter is matrix valued.

"opt_map": list

Corresponding identifiers for the parameter values.

"shots": int

Total number of measurement shots.

"memory": bool

Whether individual measurement readout is stored.

set_options(**fields)

Set the options fields for the backend

This method is used to update the options of a backend. If you need to change any of the options prior to running just pass in the kwarg with the new value for the options.

Parameters

fields – The fields to update the options

Raises

AttributeError – If the field passed in is not part of the options

configuration()

Return the backend configuration.

Returns

the configuration for the backend.

Return type

BackendConfiguration

properties()

Return the backend properties.

Returns

the configuration for the backend. If the backend does not support properties, it returns None.

Return type

BackendProperties

provider()

Return the backend Provider.

Returns

the Provider responsible for the backend.

Return type

Provider

status()

Return the backend status.

Returns

the status of the backend.

Return type

BackendStatus

name()

Return the backend name.

Returns

the name of the backend.

Return type

str

__str__()

Return str(self).

__repr__()

Official string representation of a Backend.

Note that, by Qiskit convention, it is consciously not a fully valid Python expression. Subclasses should provide ‘a string of the form <…some useful description…>’. [0]

[0] https://docs.python.org/3/reference/datamodel.html#object.__repr__

property options

Return the options for the backend

The options of a backend are the dynamic parameters defining how the backend is used. These are used to control the run() method.