Qiskit modules for C3

C3 Backend module

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

Bases: c3.qiskit.c3_backend.C3QasmSimulator

A C3-based perfect gates simulator for Qiskit

Parameters

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

DEFAULT_OPTIONS = {'initial_statevector': None, 'memory': False, 'shots': 1024}
MAX_QUBITS_MEMORY = 20
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

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

Bases: c3.qiskit.c3_backend.C3QasmSimulator

A C3-based perfect gates simulator for Qiskit

Parameters

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

DEFAULT_OPTIONS = {'initial_statevector': None, 'memory': False, 'shots': 1024}
MAX_QUBITS_MEMORY = 10
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

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

Bases: qiskit.providers.backend.BackendV1, abc.ABC

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

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

generate_shot_readout()[source]

Generate shot style readout from population

Returns

List of shots for each output state

Return type

List[int]

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

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]

run(qobj: qiskit.qobj.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),
}
abstract run_experiment(experiment: qiskit.qobj.qasm_qobj.QasmQobjExperiment) Dict[str, Any][source]
sanitize_instructions(instructions: qiskit.circuit.instruction.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

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

Set user-provided c3 experiment object for backend

Parameters

exp (Experiment) – C3 experiment object

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

C3 Provider module

class c3.qiskit.c3_provider.C3Provider[source]

Bases: qiskit.providers.provider.ProviderV1

Provider for C3 Qiskit backends

Parameters

ProviderV1 (ProviderV1) – Derived from ProviderV1 from qiskit.providers.provider

backends(name=None, filters=None, **kwargs)[source]

Return a list of backends matching the name

Parameters
  • name (str, optional) – name of the backend, by default None

  • filters (callable, optional) – Filtering conditions, as callable, by default None

Returns

A list of backend instances matching the condition

Return type

list[BackendV1]

C3 Job module

class c3.qiskit.c3_job.C3Job(backend, job_id, result)[source]

Bases: qiskit.providers.job.JobV1

C3Job class

Parameters

Job (JobV1) – Inherits JobV1 from qiskit.providers

result() qiskit.result.result.Result[source]

Return the result of the job

Returns

Result of the job simulation

Return type

qiskit.Result

status() qiskit.providers.jobstatus.JobStatus[source]

Return job status

Returns

Status of the job

Return type

qiskit.providers.JobStatus

submit() None[source]

Submit a job to the simulator

C3 Exceptions module

Exception for errors raised by Basic Aer.

exception c3.qiskit.c3_exceptions.C3QiskitError(*message)[source]

Bases: qiskit.exceptions.QiskitError

Base class for errors raised by C3 Qiskit Simulator.

C3 Gates module

Library for interoperability of c3 gates with qiskit

class c3.qiskit.c3_gates.CR90Gate(label: Optional[str] = None)[source]

Bases: qiskit.extensions.unitary.UnitaryGate

Cross Resonance 90 degree gate

Warning

This is not equivalent to the RZX(pi/2) gate in qiskit

class c3.qiskit.c3_gates.CRGate(label: Optional[str] = None)[source]

Bases: qiskit.extensions.unitary.UnitaryGate

Cross Resonance Gate

Warning

This is not equivalent to the RZX(pi/2) gate in qiskit

class c3.qiskit.c3_gates.CRXpGate[source]

Bases: qiskit.circuit.library.standard_gates.rx.CRXGate

class c3.qiskit.c3_gates.RX90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rx.RXGate

90 degree rotation around X axis in the negative direction

class c3.qiskit.c3_gates.RX90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rx.RXGate

90 degree rotation around X axis in the positive direction

class c3.qiskit.c3_gates.RXpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rx.RXGate

180 degree rotation around X axis

class c3.qiskit.c3_gates.RY90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.ry.RYGate

90 degree rotation around Y axis in the negative direction

class c3.qiskit.c3_gates.RY90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.ry.RYGate

90 degree rotation around Y axis in the positive direction

class c3.qiskit.c3_gates.RYpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.ry.RYGate

180 degree rotation around Y axis

class c3.qiskit.c3_gates.RZ90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rz.RZGate

90 degree rotation around Z axis in the negative direction

class c3.qiskit.c3_gates.RZ90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rz.RZGate

90 degree rotation around Z axis in the positive direction

class c3.qiskit.c3_gates.RZpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.standard_gates.rz.RZGate

180 degree rotation around Z axis

C3 Backend Utilities module

Convenience Module for creating different c3_backend

c3.qiskit.c3_backend_utils.flip_labels(counts: Dict[str, int]) Dict[str, int][source]

Flip C3 qubit labels to match Qiskit qubit indexing

Parameters

counts (Dict[str, int]) – OpenQasm 2.0 result counts with original C3 style qubit indices

Returns

OpenQasm 2.0 result counts with Qiskit style labels

Return type

Dict[str, int]

Note

Basis vector ordering in Qiskit

Qiskit uses a slightly different ordering of the qubits compared to what is seen in Physics textbooks. In qiskit, the qubits are represented from the most significant bit (MSB) on the left to the least significant bit (LSB) on the right (big-endian). This is similar to bitstring representation on classical computers, and enables easy conversion from bitstrings to integers after measurements are performed.

More details: https://qiskit.org/documentation/tutorials/circuits/3_summary_of_quantum_operations.html#Basis-vector-ordering-in-Qiskit

c3.qiskit.c3_backend_utils.get_init_ground_state(n_qubits: int, n_levels: int) tensorflow.python.framework.ops.Tensor[source]

Return a perfect ground state

Parameters
  • n_qubits (int) – Number of qubits in the system

  • n_levels (int) – Number of levels for each qubit

Returns

Tensor array of ground state shape(m^n, 1), dtype=complex128 m = no of qubit levels n = no of qubits

Return type

tf.Tensor

c3.qiskit.c3_backend_utils.get_sequence(instructions: List) List[str][source]

Return a sequence of c3 gates from Qasm instructions

Parameters

instructions (List[dict]) –

Instructions from the qasm experiment, for example:

instructions: [
        {"name": "u1", "qubits": [0], "params": [0.4]},
        {"name": "u2", "qubits": [0], "params": [0.4,0.2]},
        {"name": "u3", "qubits": [0], "params": [0.4,0.2,-0.3]},
        {"name": "snapshot", "label": "snapstate1", "snapshot_type": "statevector"},
        {"name": "cx", "qubits": [0,1]},
        {"name": "barrier", "qubits": [0]},
        {"name": "measure", "qubits": [0], "register": [1], "memory": [0]},
        {"name": "u2", "qubits": [0], "params": [0.4,0.2], "conditional": 2}
    ]

Returns

List of gates, for example:

sequence = ["rx90p[1]", "cr90[0,1]", "rx90p[0]"]

Return type

List[str]

c3.qiskit.c3_backend_utils.make_gate_str(instruction: dict, gate_name: str) str[source]

Make C3 style gate name string

Parameters
  • instruction (Dict[str, Any]) –

    A dict in OpenQasm instruction format

    {"name": "rx", "qubits": [0], "params": [1.57]}
    

  • gate_name (str) – C3 style gate names

Returns

C3 style gate name + qubit string

{"name": "rx", "qubits": [0], "params": [1.57]} -> rx90p[0]

Return type

str

Module contents