blueqatパッケージ

Submodules

blueqat.circuit module

This module defines Circuit and the setting for circuit.

class blueqat.circuit.BlueqatGlobalSetting[ソース]

ベースクラス: object

Setting for Blueqat.

static get_default_backend_name()[ソース]

Get the default backend name.

Returns:
str: The name of default backend.
static register_backend(name, backend, allow_overwrite=False)[ソース]

Register new backend.

Args:

name (str): The name of backend. gateclass (type): The type object of backend allow_overwrite (bool, optional): If True, allow to overwrite the existing backend.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing backend.
When allow_overwrite=True, this error is not raised.
static register_gate(name, gateclass, allow_overwrite=False)[ソース]

Register new gate to gate set.

Args:

name (str): The name of gate. gateclass (type): The type object of gate. allow_overwrite (bool, optional): If True, allow to overwrite the existing gate.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing gate.
When allow_overwrite=True, this error is not raised.
static register_macro(name: str, func: Callable, allow_overwrite: bool = False) → None[ソース]

Register new macro to Circuit.

Args:

name (str): The name of macro. func (callable): The function to be called. allow_overwrite (bool, optional): If True, allow to overwrite the existing macro.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing macro, gate or method.
When allow_overwrite=True, this error is not raised.
static remove_backend(name)[ソース]

This method is deperecated. Use unregister_backend method.

static set_default_backend(name)[ソース]

Set the default backend to be used by Circuit. Args:

name (str): The name of the default backend.
Raises:
ValueError: Specified backend is not registered.
static unregister_backend(name)[ソース]

Unregister a backend.

Args:
name (str): The name of the backend to be unregistered.
Raises:
ValueError: Specified backend is not registered.
static unregister_gate(name)[ソース]

Unregister a gate from gate set

Args:
name (str): The name of the gate to be unregistered.
Raises:
ValueError: Specified gate is not registered.
static unregister_macro(name)[ソース]

Unregister a macro.

Args:
name (str): The name of the macro to be unregistered.
Raises:
ValueError: Specified gate is not registered.
class blueqat.circuit.Circuit(n_qubits=0, ops=None)[ソース]

ベースクラス: object

Store the gate operations and call the backends.

copy(copy_backends=True, copy_default_backend=True, copy_cache=None, copy_history=None)[ソース]

Copy the circuit.

:params copy_backends :bool copy backends if True. copy_default_backend :bool copy default_backend if True.

dagger(ignore_measurement=False, copy_backends=False, copy_default_backend=True)[ソース]

Make Hermitian conjugate of the circuit.

This feature is beta. Interface may be changed.

ignore_measurement (bool, optional): If True, ignore the measurement in the circuit.
Otherwise, if measurement in the circuit, raises ValueError.
get_default_backend_name()[ソース]

Get the default backend of this circuit or global setting.

Returns:
str: The name of default backend.
make_cache(backend=None)[ソース]

Make a cache to reduce the time of run. Some backends may implemented it.

This is temporary API. It may changed or deprecated.

run(*args, backend=None, **kwargs)[ソース]

Run the circuit.

Circuit have several backends. When backend parameter is specified, use specified backend, and otherwise, default backend is used. Other parameters are passed to the backend.

The meaning of parameters are depends on the backend specifications. However, following parameters are commonly used.

Commonly used args (Depends on backend):

shots (int, optional): The number of sampling the circuit. returns (str, optional): The category of returns value.

e.g. "statevector" returns the state vector after run the circuit.
"shots" returns the counter of measured value.

token, url (str, optional): The token and URL for cloud resource.

Returns:
Depends on backend.
Raises:
Depends on backend.
set_default_backend(backend_name)[ソース]

Set the default backend of this circuit.

This setting is only applied for this circuit. If you want to change the default backend of all gates, use BlueqatGlobalSetting.set_default_backend().

After set the default backend by this method, global setting is ignored even if BlueqatGlobalSetting.set_default_backend() is called. If you want to use global default setting, call this method with backend_name=None.

Args:
backend_name (str or None): new default backend name.
If None is given, global setting is applied.
Raises:
ValueError: If backend_name is not registered backend.
to_qasm(*args, **kwargs)[ソース]

Returns the OpenQASM output of this circuit.

to_unitary(*args, **kwargs)[ソース]

Returns sympy unitary matrix of this circuit.

blueqat.gate module

gate module implements quantum gate operations. This module is internally used.

class blueqat.gate.CCZGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.Gate

2-Controlled Z gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'ccz'
class blueqat.gate.CHGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled-H gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'ch'
class blueqat.gate.CPhaseGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-Z gate but phase is different.

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cphase'
class blueqat.gate.CRXGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-X gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'crx'
class blueqat.gate.CRYGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-Y gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cry'
class blueqat.gate.CRZGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-Z gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'crz'
class blueqat.gate.CSwapGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.Gate

Controlled SWAP gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cswap'
class blueqat.gate.CU1Gate(targets, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled U1 gate

U1 gate is as same as RZ gate and CU1 gate is as same as CPhase gate. It is because for compatibility with IBM's implementations.

You should probably use RZ/CRZ gates or Phase/CPhase gates instead of U1/CU1 gates.

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cu1'
class blueqat.gate.CU2Gate(targets, phi, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled U2 gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cu2'
class blueqat.gate.CU3Gate(targets, theta, phi, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled U3 gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cu3'
class blueqat.gate.CXGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled-X (CNOT) gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'cx'
class blueqat.gate.CYGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled-Y gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'cy'
class blueqat.gate.CZGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Controlled-Z gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'cz'
class blueqat.gate.Gate(targets, params=(), **kwargs)[ソース]

ベースクラス: abc.ABC

Abstract quantum gate class.

dagger() → blueqat.gate.Gate[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits: int) → List[blueqat.gate.Gate][ソース]

Returns alternative gates to make equivalent circuit.

lowername = None
uppername

Upper name of the gate.

class blueqat.gate.HGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Hadamard gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'h'
class blueqat.gate.IGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Identity gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'i'
class blueqat.gate.Measurement(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Measurement operation

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'measure'
class blueqat.gate.OneQubitGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.Gate

Abstract quantum gate class for 1 qubit gate.

target_iter(n_qubits)[ソース]

The generator which yields the target qubits.

class blueqat.gate.PhaseGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Rotate-Z gate but global phase is different.

Global phase doesn't makes any difference of measured result. You may use RZ gate or U1 gate instead, but distinguishing these gates may better for debugging or future improvement.

furthermore, phase gate may efficient for simulating. (It depends on backend implementation. But matrix of phase gate is simpler than RZ gate or U1 gate.)

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'phase'
class blueqat.gate.RXGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Rotate-X gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'rx'
class blueqat.gate.RXXGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-XX gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'rxx'
class blueqat.gate.RYGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Rotate-Y gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'ry'
class blueqat.gate.RYYGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-YY gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'ryy'
class blueqat.gate.RZGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Rotate-Z gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'rz'
class blueqat.gate.RZZGate(targets, theta, **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Rotate-ZZ gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'rzz'
class blueqat.gate.Reset(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Reset operation

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'reset'
class blueqat.gate.SDagGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Dagger of S gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'sdg'
class blueqat.gate.SGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

S gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 's'
class blueqat.gate.SwapGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.TwoQubitGate

Swap gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'swap'
class blueqat.gate.TDagGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Dagger of T ($pi/8$) gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'tdg'
class blueqat.gate.TGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

T ($pi/8$) gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 't'
class blueqat.gate.ToffoliGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.Gate

Toffoli (CCX) gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'ccx'
class blueqat.gate.TwoQubitGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.Gate

Abstract quantum gate class for 2 qubits gate.

control_target_iter(n_qubits)[ソース]

The generator which yields the tuples of (control, target) qubits.

class blueqat.gate.U1Gate(targets, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

U1 gate

U1 gate is as same as RZ gate and CU1 gate is as same as CPhase gate. It is because for compatibility with IBM's implementations.

You should probably use RZ/CRZ gates or Phase/CPhase gates instead of U1/CU1 gates.

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'u1'
class blueqat.gate.U2Gate(targets, phi, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

U2 gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

fallback(n_qubits)[ソース]

Returns alternative gates to make equivalent circuit.

lowername = 'u2'
class blueqat.gate.U3Gate(targets, theta, phi, lambd, **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

U3 gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'u3'
class blueqat.gate.XGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Pauli's X gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'x'
class blueqat.gate.YGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Pauli's Y gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'y'
class blueqat.gate.ZGate(targets, params=(), **kwargs)[ソース]

ベースクラス: blueqat.gate.OneQubitGate

Pauli's Z gate

dagger()[ソース]

Returns the Hermitian conjugate of self.

lowername = 'z'
blueqat.gate.find_n_qubits(gates)[ソース]

Find n_qubits from gates

blueqat.gate.get_maximum_index(indices)[ソース]

Internally used.

blueqat.gate.qubit_pairs(args, length)[ソース]

Internally used.

blueqat.gate.slicing(args, length)[ソース]

Internally used.

blueqat.gate.slicing_singlevalue(arg, length)[ソース]

Internally used.

blueqat.pauli module

The module for calculate Pauli matrices.

class blueqat.pauli.Expr[ソース]

ベースクラス: blueqat.pauli._ExprTuple

coeffs()[ソース]

Generator which yields a coefficent for each Term.

commutator(other)[ソース]

Returns commutator.

static from_number(num)[ソース]

Make new Expr from a number

static from_term(term)[ソース]

Make new Expr from a Term

static from_terms_dict(terms_dict)[ソース]

For internal use.

static from_terms_iter(terms)[ソース]

For internal use.

is_all_terms_commutable()[ソース]

Test whether all terms are commutable. This function may very slow.

is_commutable_with(other)[ソース]

Test whether self is commutable with other.

max_n()[ソース]

Returns the maximum index of Pauli matrices in the Expr. If Expr is empty or only constant and identity matrix, returns -1.

simplify()[ソース]

Simplify the Expr.

terms_to_dict()[ソース]

For internal use.

to_expr()[ソース]

Do nothing. This method is prepared to avoid TypeError.

to_matrix(n_qubits=-1, *, sparse=None)[ソース]

Convert to the matrix.

static zero()[ソース]

Returns 0 as Term

is_identity

If self is I, returns True, otherwise False.

n_qubits

Returns the number of qubits of the Term.

If Expr is empty or only constant and identity matrix, returns 0.

class blueqat.pauli.Term[ソース]

ベースクラス: blueqat.pauli._TermTuple

Multiplication of Pauli matrices with coefficient. Note that this class is immutable.

Multiplied Pauli matrices are very important for quantum computation because it is an unitary matrix (without coefficient) and also it can be consider the time evolution of the term (with real coefficient) without Suzuki-Trotter expansion.

append_to_circuit(circuit, simplify=True)[ソース]

Append Pauli gates to Circuit.

commutator(other)[ソース]

Returns commutator.

static from_chars(chars)[ソース]

Make Pauli's Term from chars which is written by "X", "Y", "Z" or "I". e.g. "XZIY" => X(0) * Z(1) * Y(3)

Args:
chars (str): Written in "X", "Y", "Z" or "I".
Returns:
Term: A Term object.
Raises:
ValueError: When chars conteins the character which is "X", "Y", "Z" nor "I".
static from_ops_iter(ops, coeff)[ソース]

For internal use.

static from_pauli(pauli, coeff=1.0)[ソース]

Make new Term from an Pauli operator

static from_paulipair(pauli1, pauli2)[ソース]

Make new Term from two Pauli operator.

get_time_evolution()[ソース]

Get the function to append the time evolution of this term.

Returns:
function(circuit: Circuit, t: float):
Add gates for time evolution to circuit with time t
is_commutable_with(other)[ソース]

Test whether self is commutable with other.

static join_ops(ops1, ops2)[ソース]

For internal use.

max_n()[ソース]

Returns the maximum index of Pauli matrices in the Term. If there's no Pauli matrices, returns -1.

n_iter()[ソース]

Returns an iterator which yields indices for each Pauli matrices in the Term.

simplify()[ソース]

Simplify the Term.

to_expr()[ソース]

Convert to Expr.

to_matrix(n_qubits=-1, *, sparse=None)[ソース]

Convert to the matrix.

to_term()[ソース]

Do nothing. This method is prepared to avoid TypeError.

is_identity

If self is I, returns True, otherwise False.

n_qubits

Returns the number of qubits of the term. If the term is constant with identity matrix, n_qubits is 0.

blueqat.pauli.commutator(expr1, expr2)[ソース]

Returns [expr1, expr2] = expr1 * expr2 - expr2 * expr1.

Args:
expr1 (Expr, Term or Pauli operator): Pauli's expression. expr2 (Expr, Term or Pauli operator): Pauli's expression.
Returns:
Expr: expr1 * expr2 - expr2 * expr1.
blueqat.pauli.is_commutable(expr1, expr2, eps=1e-08)[ソース]

Test whether expr1 and expr2 are commutable.

Args:

expr1 (Expr, Term or Pauli operator): Pauli's expression. expr2 (Expr, Term or Pauli operator): Pauli's expression. eps (float, optional): Machine epsilon.

If |[expr1, expr2]| < eps, consider it is commutable.
Returns:
bool: if expr1 and expr2 are commutable, returns True, otherwise False.
blueqat.pauli.pauli_from_char(ch, n=0)[ソース]

Make Pauli matrix from an character.

Args:
ch (str): "X" or "Y" or "Z" or "I". n (int, optional): Make Pauli matrix as n-th qubits.
Returns:
If ch is "X" => X, "Y" => Y, "Z" => Z, "I" => I
Raises:
ValueError: When ch is not "X", "Y", "Z" nor "I".
blueqat.pauli.qubo_bit(n)[ソース]

Represent QUBO's bit to Pauli operator of Ising model.

Args:
n (int): n-th bit in QUBO
Returns:
Expr: Pauli expression of QUBO bit.
blueqat.pauli.term_from_chars(chars)[ソース]

Make Pauli's Term from chars which is written by "X", "Y", "Z" or "I". e.g. "XZIY" => X(3) * Z(2) * Y(0)

Args:
chars (str): Written in "X", "Y", "Z" or "I".
Returns:
Term: A Term object.
Raises:
ValueError: When chars conteins the character which is "X", "Y", "Z" nor "I".
blueqat.pauli.to_expr(term)[ソース]

Convert to Expr from Term or Pauli operator (X, Y, Z, I).

Args:
term: (Term, X, Y, Z or I): A Term or Pauli operator.
Returns:
Expr: An Expr object.
blueqat.pauli.to_term(pauli)[ソース]

Convert to Term from Pauli operator (X, Y, Z, I).

Args:
pauli (X, Y, Z or I): A Pauli operator
Returns:
Term: A Term object.

blueqat.vqe module

class blueqat.vqe.AnsatzBase(hamiltonian, n_params)[ソース]

ベースクラス: object

get_circuit(params)[ソース]

Make a circuit from parameters.

get_energy(circuit, sampler)[ソース]

Calculate energy from circuit and sampler.

get_energy_sparse(circuit)[ソース]

Get energy using sparse matrix. This method may be changed in the future release.

get_objective(sampler=None)[ソース]

Get an objective function to be optimized.

make_sparse(fmt='csc', make_method=None)[ソース]

Make sparse matrix. This method may be changed in the future release.

class blueqat.vqe.QaoaAnsatz(hamiltonian, step=1, init_circuit=None, mixer=None)[ソース]

ベースクラス: blueqat.vqe.AnsatzBase

Ansatz for QAOA.

check_hamiltonian()[ソース]

Check hamiltonian is commutable. This condition is required for QaoaAnsatz

get_circuit(params)[ソース]

Make a circuit from parameters.

class blueqat.vqe.Vqe(ansatz, minimizer=None, sampler=None)[ソース]

ベースクラス: object

run(verbose=False)[ソース]
result

Vqe.result is deprecated. Use result = Vqe.run().

class blueqat.vqe.VqeResult(vqe=None, params=None, circuit=None)[ソース]

ベースクラス: object

get_probs(sampler=None, rerun=None, store=True)[ソース]

Get probabilities.

most_common(n=1)[ソース]
probs

Get probabilities. This property is obsoleted. Use get_probs().

blueqat.vqe.expect(qubits, meas)[ソース]

For the VQE simulation without sampling.

blueqat.vqe.get_measurement_sampler(n_sample, run_options=None)[ソース]

Returns a function which get the expectations by sampling the measured circuit

blueqat.vqe.get_qiskit_sampler(backend, **execute_kwargs)[ソース]

Returns a function which get the expectation by sampling via Qiskit.

This function requires qiskit module.

blueqat.vqe.get_scipy_minimizer(**kwargs)[ソース]

Get minimizer which uses scipy.optimize.minimize

blueqat.vqe.get_state_vector_sampler(n_sample)[ソース]

Returns a function which get the expectations by sampling the state vector

blueqat.vqe.non_sampling_sampler(circuit, meas)[ソース]

Calculate the expectations without sampling.

blueqat.vqe.sparse_expectation(mat, vec)[ソース]

Calculate expectation value <vec|mat|vec>.

Args:
mat (scipy sparse matrix): Sparse matrix vec (numpy array): Vector
Returns:
(Real part of) expectation value <vec|mat|vec>. Remarks: when mat is Hermitian, <vec|mat|vec> is real.

Module contents

class blueqat.Circuit(n_qubits=0, ops=None)[ソース]

ベースクラス: object

Store the gate operations and call the backends.

copy(copy_backends=True, copy_default_backend=True, copy_cache=None, copy_history=None)[ソース]

Copy the circuit.

:params copy_backends :bool copy backends if True. copy_default_backend :bool copy default_backend if True.

dagger(ignore_measurement=False, copy_backends=False, copy_default_backend=True)[ソース]

Make Hermitian conjugate of the circuit.

This feature is beta. Interface may be changed.

ignore_measurement (bool, optional): If True, ignore the measurement in the circuit.
Otherwise, if measurement in the circuit, raises ValueError.
get_default_backend_name()[ソース]

Get the default backend of this circuit or global setting.

Returns:
str: The name of default backend.
make_cache(backend=None)[ソース]

Make a cache to reduce the time of run. Some backends may implemented it.

This is temporary API. It may changed or deprecated.

run(*args, backend=None, **kwargs)[ソース]

Run the circuit.

Circuit have several backends. When backend parameter is specified, use specified backend, and otherwise, default backend is used. Other parameters are passed to the backend.

The meaning of parameters are depends on the backend specifications. However, following parameters are commonly used.

Commonly used args (Depends on backend):

shots (int, optional): The number of sampling the circuit. returns (str, optional): The category of returns value.

e.g. "statevector" returns the state vector after run the circuit.
"shots" returns the counter of measured value.

token, url (str, optional): The token and URL for cloud resource.

Returns:
Depends on backend.
Raises:
Depends on backend.
set_default_backend(backend_name)[ソース]

Set the default backend of this circuit.

This setting is only applied for this circuit. If you want to change the default backend of all gates, use BlueqatGlobalSetting.set_default_backend().

After set the default backend by this method, global setting is ignored even if BlueqatGlobalSetting.set_default_backend() is called. If you want to use global default setting, call this method with backend_name=None.

Args:
backend_name (str or None): new default backend name.
If None is given, global setting is applied.
Raises:
ValueError: If backend_name is not registered backend.
to_qasm(*args, **kwargs)[ソース]

Returns the OpenQASM output of this circuit.

to_unitary(*args, **kwargs)[ソース]

Returns sympy unitary matrix of this circuit.

class blueqat.BlueqatGlobalSetting[ソース]

ベースクラス: object

Setting for Blueqat.

static get_default_backend_name()[ソース]

Get the default backend name.

Returns:
str: The name of default backend.
static register_backend(name, backend, allow_overwrite=False)[ソース]

Register new backend.

Args:

name (str): The name of backend. gateclass (type): The type object of backend allow_overwrite (bool, optional): If True, allow to overwrite the existing backend.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing backend.
When allow_overwrite=True, this error is not raised.
static register_gate(name, gateclass, allow_overwrite=False)[ソース]

Register new gate to gate set.

Args:

name (str): The name of gate. gateclass (type): The type object of gate. allow_overwrite (bool, optional): If True, allow to overwrite the existing gate.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing gate.
When allow_overwrite=True, this error is not raised.
static register_macro(name: str, func: Callable, allow_overwrite: bool = False) → None[ソース]

Register new macro to Circuit.

Args:

name (str): The name of macro. func (callable): The function to be called. allow_overwrite (bool, optional): If True, allow to overwrite the existing macro.

Otherwise, raise the ValueError.
Raises:
ValueError: The name is duplicated with existing macro, gate or method.
When allow_overwrite=True, this error is not raised.
static remove_backend(name)[ソース]

This method is deperecated. Use unregister_backend method.

static set_default_backend(name)[ソース]

Set the default backend to be used by Circuit. Args:

name (str): The name of the default backend.
Raises:
ValueError: Specified backend is not registered.
static unregister_backend(name)[ソース]

Unregister a backend.

Args:
name (str): The name of the backend to be unregistered.
Raises:
ValueError: Specified backend is not registered.
static unregister_gate(name)[ソース]

Unregister a gate from gate set

Args:
name (str): The name of the gate to be unregistered.
Raises:
ValueError: Specified gate is not registered.
static unregister_macro(name)[ソース]

Unregister a macro.

Args:
name (str): The name of the macro to be unregistered.
Raises:
ValueError: Specified gate is not registered.