polyadicqml.manyq

polyadicqml.manyq.mqBuilder

class polyadicqml.manyq.mqBuilder(nbqbits, batch_size, *args, gpu=False, **kwargs)

Builder for circuits to be run on manyQ simulator.

alldiam(idx=None)

Add X-rotation of \pi/2.

Parameters

idx (iterable, optional) – Indices on which to apply the rotation, by default None. If None, apply to all qubits.

Returns

self

Return type

circuitBuilder

Raises
  • ValueError – If idx is out of range

  • TypeError – If the indices are not int

allin(theta)

Add input gate to all qubits and input theta.

Parameters

theta (list-like) – Parameters to input.

Returns

self

Return type

circuitBuilder

circuit()

Return the built circuit.

Returns

Return type

quantum circuit

cz(a, b)

Add CZ gate between qubits a and b

Parameters
  • a (int) – Control qubit

  • b (int) – Target qubit.

Returns

self

Return type

circuitBuilder

Raises
  • ValueError – If a or b are out of range

  • TypeError – If the indices are not int

input(idx, theta)

Add input gate.

It correspond to a rotation of RX(\pi/2) RZ(theta) RX(\pi/2).

Parameters
  • idx (Union[iterable, int]) – Index[-ices] of qubits on which to input theta.

  • theta (Union[list-like, float]) – Parameter[s] to input. Has to have the same length as idx.

Returns

self

Return type

circuitBuilder

Raises
  • ValueError – If idx is out of range

  • TypeError – If the indices are not int

measure_all()

Add measurement.

Returns

self

Return type

circuitBuilder

polyadicqml.manyq.mqCircuitML

class polyadicqml.manyq.mqCircuitML(make_circuit, nbqbits, nbparams, gpu=False, cbuilder=<class 'polyadicqml.manyq.mqBuilder.mqBuilder'>)

Quantum ML circuit interface for manyq simulator. Provides a unified interface to run multiple parametric circuits with different input and model parameters.

Parameters
  • make_circuit (callable of signature self.make_circuit) – Function to generate the circuit corresponding to input x and params.

  • nbqbits (int) – Number of qubits.

  • nbparams (int) – Number of parameters.

  • cbuilder (circuitBuilder, optional) – Circuit builder, by default mqBuilder

nbqbits

Number of qubits.

Type

int

nbparams

Number of parameters.

Type

int

Raises

ValueError – If both noise_model and noise_backend are provided.

cpu()

Switch to numpy.

gpu()

Switch to cupy.

run(X, params, nbshots=None, job_size=None)

Run the circuit with input X and parameters params.

Parameters
  • X (array-like) – Input matrix of shape (nb_samples, nb_features).

  • params (vector-like) – Parameter vector.

  • nbshots (int, optional) – Number of shots for the circuit run, by default None. If None, uses the backend default.

  • job_size (int, optional) – Maximum job size, to split the circuit runs, by default None. If None, put all nb_samples in the same job.

Returns

Bitstring counts as an array of shape (nb_samples, 2**nbqbits)

Return type

array