Home Reference Source
import IBMBackend from 'projectq/src/backends/ibm/ibm.js'
public class | source

IBMBackend

Extends:

BasicEngine → IBMBackend

The IBM Backend class, which stores the circuit, transforms it to JSON QASM, and sends the circuit through the IBM API.

Constructor Summary

Public Constructor
public

constructor(args: {use_hardware: boolean, num_runs: number, verbose: boolean, user: string, password: string, device: string, retrieve_execution: ?string})

Member Summary

Public Members
public

device: *

public get
public set
public get

errors: Error[]: *

public
Private Members
private
private
private
private

_errors: *[]

private
private
private
private
private
private

_user: *

private

Method Summary

Public Methods
public

addError(error: *)

public

Return the list of basis states with corresponding probabilities.

public

Return true if the command can be executed.

public

receive(commandList: Command[])

Receives a command list and, for each command, stores it until completion.

public

async run()

Run the circuit.

Private Methods
private

Return the physical location of the qubit with the given logical id.

private

_reset()

private

_store(cmd: Command)

Temporarily store the command cmd.

Inherited Summary

From class BasicEngine
public
public

Return a new qubit as a list containing 1 qubit object (quantum register of size 1).

public

Allocate n qubits and return them as a quantum register, which is a list of qubit objects.

public

Deallocate a qubit (and sends the deallocation command down the pipeline).

public

Default implementation of isAvailable: Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s).

public

Check if there is a compiler engine handling the meta tag

public
public

send(commandList: Command[])

Forward the list of commands to the next engine in the pipeline.

Public Constructors

public constructor(args: {use_hardware: boolean, num_runs: number, verbose: boolean, user: string, password: string, device: string, retrieve_execution: ?string}) source

Override:

BasicEngine#constructor

Params:

NameTypeAttributeDescription
args {use_hardware: boolean, num_runs: number, verbose: boolean, user: string, password: string, device: string, retrieve_execution: ?string}

use_hardware: If true, the code is run on the IBM quantum chip (instead of using the IBM simulator) num_runs: Number of runs to collect statistics. (default is 1024) verbose: If true, statistics are printed, in addition to the measurement result being registered (at the end of the circuit). user: IBM Quantum Experience user name password: IBM Quantum Experience password device: Device to use ('ibmqx4', or 'ibmqx5') if use_hardware is set to true. Default is ibmqx4. retrieve_execution: Job ID to retrieve instead of re-running the circuit (e.g., if previous run timed out).

Public Members

public device: * source

public get didRunCallback: function: * source

Return:

function

public set didRunCallback(callback: function) source

public get errors: Error[]: * source

Return:

Error[]

public qasm: string source

Private Members

private _allocated_qubits: * source

private _clear: boolean source

private _didRunCallback: * source

private _errors: *[] source

private _measured_ids: *[] source

private _num_runs: * source

private _password: * source

private _probabilities: {} source

private _retrieve_execution: * source

private _user: * source

private _verbose: * source

Public Methods

public addError(error: *) source

Params:

NameTypeAttributeDescription
error *

public getProbabilities(qureg: Array<Qubit> | Qureg): Object source

Return the list of basis states with corresponding probabilities.

The measured bits are ordered according to the supplied quantum register, i.e., the left-most bit in the state-string corresponds to the first qubit in the supplied quantum register.

Warning: Only call this function after the circuit has been executed!

Params:

NameTypeAttributeDescription
qureg Array<Qubit> | Qureg

Quantum register determining the order of the qubits.

Return:

Object

Dictionary mapping n-bit strings to probabilities.

Throw:

Error

If no data is available (i.e., if the circuit has not been executed). Or if a qubit was supplied which was not present in the circuit (might have gotten optimized away).

public isAvailable(cmd: Command): boolean source

Return true if the command can be executed.

The IBM quantum chip can do X, Y, Z, T, Tdag, S, Sdag, rotation gates, barriers, and CX / CNOT.

Override:

BasicEngine#isAvailable

Params:

NameTypeAttributeDescription
cmd Command

Command for which to check availability

Return:

boolean

public receive(commandList: Command[]) source

Receives a command list and, for each command, stores it until completion.

Override:

BasicEngine#receive

Params:

NameTypeAttributeDescription
commandList Command[]

List of commands to execute

public async run() source

Run the circuit.

Send the circuit via the IBM API (JSON QASM) using the provided user data / ask for username & password.

Private Methods

private _logicalToPhysical(qbID: number): * source

Return the physical location of the qubit with the given logical id.

Params:

NameTypeAttributeDescription
qbID number

ID of the logical qubit whose position should be returned.

Return:

*

private _reset() source

private _store(cmd: Command) source

Temporarily store the command cmd.

Translates the command and stores it in a local variable (this._cmds).

Params:

NameTypeAttributeDescription
cmd Command

Command to store