Skip to content

Simulator

numqi.sim

numqi.sim.new_base(num_qubit, dtype=np.complex128)

return the base state of the qubit quantum system

Parameters:

Name Type Description Default
num_qubit int

the number of qubits

required
dtype dtype

the data type of the base state

complex128

Returns:

Name Type Description
ret ndarray

the base state

numqi.sim.Circuit

Quantum circuit simulator class

H = _unitary_gate('H', numqi.gate.H, 1) class-attribute instance-attribute

Hadamard gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

S = _unitary_gate('S', numqi.gate.S, 1) class-attribute instance-attribute

S gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

Swap = _unitary_gate('Swap', numqi.gate.Swap, 2) class-attribute instance-attribute

Swap gate

Parameters:

Name Type Description Default
index0 int

the index of the first qubit

required
index1 int

the index of the second qubit

required
name str

the name of the gate

required

T = _unitary_gate('T', numqi.gate.T, 1) class-attribute instance-attribute

T gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

X = _unitary_gate('X', numqi.gate.pauli.sx, 1) class-attribute instance-attribute

Pauli-X gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

Y = _unitary_gate('Y', numqi.gate.pauli.sy, 1) class-attribute instance-attribute

Pauli-Y gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

Z = _unitary_gate('Z', numqi.gate.pauli.sz, 1) class-attribute instance-attribute

Pauli-Z gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
name str

the name of the gate

required

cnot = _control_gate('cnot', numqi.gate.pauli.sx, 1, 1) class-attribute instance-attribute

CNOT gate

Parameters:

Name Type Description Default
control_qubit int

the index of the control qubit

required
target_qubit int

the index of the target qubit

required
name str

the name of the gate

required

cx = cnot class-attribute instance-attribute

CNOT gate

Parameters:

Name Type Description Default
control_qubit int

the index of the control qubit

required
target_qubit int

the index of the target qubit

required
name str

the name of the gate

required

cy = _control_gate('cy', numqi.gate.pauli.sy, 1, 1) class-attribute instance-attribute

Controlled-Y gate

Parameters:

Name Type Description Default
control_qubit int

the index of the control qubit

required
target_qubit int

the index of the target qubit

required
name str

the name of the gate

required

cz = _control_gate('cz', numqi.gate.pauli.sz, 1, 1) class-attribute instance-attribute

Controlled-Z gate

Parameters:

Name Type Description Default
control_qubit int

the index of the control qubit

required
target_qubit int

the index of the target qubit

required
name str

the name of the gate

required

num_qubit property

number of qubits in the circuit

rx = _unitary_parameter_gate('rx', numqi.gate.rx, 1, 1) class-attribute instance-attribute

Rotation-X gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
args (float, None)

the angle of rotation, if None, then initialize to zero

required
name str

the name of the gate

required
requires_grad (bool, None)

whether the angle of rotation is trainable, if None, then use the default value set in the circuit

required

Returns:

Name Type Description
ret ParameterGate

the gate

ry = _unitary_parameter_gate('ry', numqi.gate.ry, 1, 1) class-attribute instance-attribute

Rotation-Y gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
args (float, None)

the angle of rotation, if None, then initialize to zero

required
name str

the name of the gate

required
requires_grad (bool, None)

whether the angle of rotation is trainable, if None, then use the default value set in the circuit

required

Returns:

Name Type Description
ret ParameterGate

the gate

rz = _unitary_parameter_gate('rz', numqi.gate.rz, 1, 1) class-attribute instance-attribute

Rotation-Z gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
args (float, None)

the angle of rotation, if None, then initialize to zero

required
name str

the name of the gate

required
requires_grad (bool, None)

whether the angle of rotation is trainable, if None, then use the default value set in the circuit

required

Returns:

Name Type Description
ret ParameterGate

the gate

toffoli = _control_gate('toffoli', numqi.gate.pauli.sx, 2, 1) class-attribute instance-attribute

Toffoli gate

Parameters:

Name Type Description Default
control_qubit tuple[int]

the indexs of the first control qubit, len=2

required
target_qubit int

the index of the target qubit

required
name str

the name of the gate

required

u3 = _unitary_parameter_gate('u3', numqi.gate.u3, 1, 3) class-attribute instance-attribute

U-3 gate

Parameters:

Name Type Description Default
index int

the index of the qubit

required
args (tuple[float], None)

the angles of rotation, if None, then initialize to (0,0,0)

required
name str

the name of the gate

required
requires_grad (bool, None)

whether the angle of rotation is trainable, if None, then use the default value set in the circuit

required

Returns:

Name Type Description
ret ParameterGate

the gate

__init__(default_requires_grad=False)

initialize the circuit

Parameters:

Name Type Description Default
default_requires_grad bool

default value of requires_grad for the parameterized gate

False

append_gate(gate, index)

append a gate to the circuit. Trainable parameters are re-used.

Parameters:

Name Type Description Default
gate Gate

the gate to be appended

required
index tuple[int]

the index of the gate

required

apply_state(q0)

apply the circuit to a quantum state

Parameters:

Name Type Description Default
q0 ndarray

the quantum state, shape=(2**num_qubit,)

required

Returns:

Name Type Description
ret ndarray

the quantum state after the circuit, shape=(2**num_qubit,)

controlled_double_qubit_gate(np0, ind_control_set, ind_target, name='control')

append a controlled double qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(4,4)

required
ind_control_set set[int]

the index of the control qubits

required
ind_target tuple[int]

the index of the target qubits, len=2

required
name str

the name of the gate

'control'

controlled_single_qubit_gate(np0, ind_control_set, ind_target, name='control')

append a controlled single qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(2,2)

required
ind_control_set set[int]

the index of the control qubits

required
ind_target int

the index of the target qubit

required
name str

the name of the gate

'control'

double_qubit_gate(np0, ind0, ind1, name='double')

append a double qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(4,4)

required
ind0 int

the index of the first qubit

required
ind1 int

the index of the second qubit

required
name str

the name of the gate

'double'

extend_circuit(circ0)

extend the circuit by another circuit. Trainable parameters are re-used.

Parameters:

Name Type Description Default
circ0 Circuit

the circuit to be extended

required

measure(index, seed=None, name='measure')

append a measure gate to the circuit

Parameters:

Name Type Description Default
index (int, tuple[int])

the index of the qubit

required
seed (int, None)

the seed of the random number generator

None
name str

the name of the gate

'measure'

quadruple_qubit_gate(np0, ind0, ind1, ind2, ind3, name='quadruple')

append a quadruple qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(16,16)

required
ind0 int

the index of the first qubit

required
ind1 int

the index of the second qubit

required
ind2 int

the index of the third qubit

required
ind3 int

the index of the fourth qubit

required
name str

the name of the gate

'quadruple'

register_custom_gate(name, gate_class)

register a custom gate to the circuit

Parameters:

Name Type Description Default
name str

the name of the gate

required
gate_class type

user-defined gate class

required

shift_qubit_index_(delta)

shift the index of the qubits in the circuit in-place

Parameters:

Name Type Description Default
delta int

the shift of the index

required

single_qubit_gate(np0, ind0, name='single')

append a single qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(2,2)

required
ind0 int

the index of the qubit

required
name str

the name of the gate

'single'

triple_qubit_gate(np0, ind0, ind1, ind2, name='triple')

append a triple qubit gate to the circuit

Parameters:

Name Type Description Default
np0 ndarray

the unitary matrix of the gate, shape=(8,8)

required
ind0 int

the index of the first qubit

required
ind1 int

the index of the second qubit

required
ind2 int

the index of the third qubit

required
name str

the name of the gate

'triple'