Qiskit modules for C3¶
C3 Backend module¶
- class c3.qiskit.c3_backend.C3QasmPerfectSimulator(configuration=None, provider=None, **fields)[source]¶
Bases:
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
- class c3.qiskit.c3_backend.C3QasmPhysicsSimulator(configuration=None, provider=None, **fields)[source]¶
Bases:
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
- MAX_QUBITS_MEMORY = 10¶
- run_experiment(experiment: 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:
BackendV1
,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: Qobj, **backend_options) 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
- 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.
- sanitize_instructions(instructions: 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: Experiment) None [source]¶
Set user-provided c3 experiment object for backend
- Parameters
exp (Experiment) – C3 experiment object
C3 Provider module¶
- class c3.qiskit.c3_provider.C3Provider[source]¶
Bases:
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:
JobV1
C3Job class
- Parameters
Job (JobV1) – Inherits JobV1 from qiskit.providers
- result() Result [source]¶
Return the result of the job
- Returns
Result of the job simulation
- Return type
qiskit.Result
C3 Exceptions module¶
Exception for errors raised by Basic Aer.
C3 Gates module¶
Library for interoperability of c3 gates with qiskit
- class c3.qiskit.c3_gates.CR90Gate(label: Optional[str] = None)[source]¶
Bases:
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:
UnitaryGate
Cross Resonance Gate
Warning
This is not equivalent to the RZX(pi/2) gate in qiskit
- class c3.qiskit.c3_gates.RX90mGate(label: Optional[str] = None)[source]¶
Bases:
RXGate
90 degree rotation around X axis in the negative direction
- class c3.qiskit.c3_gates.RX90pGate(label: Optional[str] = None)[source]¶
Bases:
RXGate
90 degree rotation around X axis in the positive direction
- class c3.qiskit.c3_gates.RXpGate(label: Optional[str] = None)[source]¶
Bases:
RXGate
180 degree rotation around X axis
- class c3.qiskit.c3_gates.RY90mGate(label: Optional[str] = None)[source]¶
Bases:
RYGate
90 degree rotation around Y axis in the negative direction
- class c3.qiskit.c3_gates.RY90pGate(label: Optional[str] = None)[source]¶
Bases:
RYGate
90 degree rotation around Y axis in the positive direction
- class c3.qiskit.c3_gates.RYpGate(label: Optional[str] = None)[source]¶
Bases:
RYGate
180 degree rotation around Y axis
- class c3.qiskit.c3_gates.RZ90mGate(label: Optional[str] = None)[source]¶
Bases:
RZGate
90 degree rotation around Z axis in the negative direction
- class c3.qiskit.c3_gates.RZ90pGate(label: Optional[str] = None)[source]¶
Bases:
RZGate
90 degree rotation around Z axis in the positive direction
- class c3.qiskit.c3_gates.RZpGate(label: Optional[str] = None)[source]¶
Bases:
RZGate
180 degree rotation around Z axis
- class c3.qiskit.c3_gates.SetParamsGate(params: List)[source]¶
Bases:
Gate
Gate for setting parameter values through qiskit interface. This gate is only processed when it is the last gate in the circuit, otherwise it throws a KeyError. The qubit target for the gate can be any valid qubit in the circuit, this argument is currently ignored and not processed by the backend
These parameters should be supplied as a list with the first item a list of Quantity objects converted to a Dict of Python primitives and the second item an opt_map with the proper list nesting. For example:
amp = Qty(value=0.8, min_val=0.2, max_val=1, unit="V") opt_map = [[["rx90p[0]", "d1", "gaussian", "amp"]]] param_gate = SetParamsGate(params=[[amp.asdict()], opt_map])
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) 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.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