qupy package

Submodules

qupy.operator module

qupy.operator.iqft(n)
qupy.operator.phase_shift(phi)
qupy.operator.qft(n)
qupy.operator.rx(phi)
qupy.operator.ry(phi)
qupy.operator.rz(phi)

qupy.qubit module

class qupy.qubit.Qubits(size, **kargs)

Bases: object

Creating qubits.

Args:
size (int):
Number of qubits.
dtype:
Data type of the data array.
gpu (int):
GPU machine number.
Attributes:
data (numpy.ndarray or cupy.ndarray):
The state of qubits.
size:
Number of qubits.
dtype:
Data type of the data array.
expect(self, observable)

Method to get expected value of observable.

Args:
observable (dict or numpy.ndarray or cupy.ndarray):
Physical quantity operator. If you input numpy.ndarray or cupy.ndarray as observable, this method returns \(\langle \psi | \mathrm{observable} | \psi \rangle\), where \(| \psi \rangle\) is the states of qubits. If you use dict input, you have to set {‘operator1’: coef1, ‘operator2’: coef2, ‘operator3’: coef3, …}, such as {‘XIX’: 0.32, ‘YYZ’: 0.11, ‘III’: 0.02}. If you input dict as observable, this method returns \(\sum_i \mathrm{coef}i \langle \psi | \mathrm{operator}i | \psi \rangle\).
n_trial (:class: int):
cumulative number.
Returns:
float: Expected value.
gate(self, operator, target, control=None, control_0=None)

Gate method.

Args:
operator (numpy.ndarray or cupy.ndarray):
Unitary operator
target (None or int or tuple of int):
Operated qubits
control (None or int or tuple of int):
Operate target qubits where all control qubits are 1
control_0 (None or int or tuple of int):
Operate target qubits where all control qubits are 0
get_state(self, flatten=True)

Get state.

Args:
flatten (bool):
If you set flatten=False, you can get data format used in QuPy. otherwise, you get state reformated to 1D-array.
project(target)

projection(self, target)

Projection method.

Args:
target (None or int or tuple of int):
projected qubits
Returns:
int: O or 1.
set_state(self, state)

Set state.

Args:
state (str or list or numpy.ndarray or cupy.ndarray):
If you set state as str, you can set state \(|\mathrm{state}\rangle\) (e.g. state=‘0110’ -> \(|0110\rangle\).) otherwise, qubit state is set that you entered as state.

Module contents