GithubHelp home page GithubHelp logo

raijeku / qmeans Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 3.0 3.14 MB

Q-Means algorithm implementation using Qiskit compatible with Scikit-Learn.

Home Page: https://qmeans.readthedocs.io/

License: Apache License 2.0

Python 100.00%

qmeans's Introduction

Hi there, I'm David 👋

  • 🔭 I’m currently working on optimizing pulses on IBM quantum devices, analyzing my quantum k-means implementation, quantum walks and constellation modulation. I'm also working on my personal website!
  • 🌱 I’m currently learning about the Quantum Approximate Optimization Algorithm (QAOA), quantum walks and constellation diagrams in optics.
  • 👯 I’m looking to collaborate on quantum machine learning and quantum benchmarking projects. Classical machine learning application projects too.
  • 🤔 I’m looking for help with improving my open source projects.
  • 💬 Ask me about anything math or quantum related.
  • 📫 How to reach me: Email me at [email protected]
  • ⚡ Fun fact: I love learning in general, be it languages, physics or just interesting stuff.

qmeans's People

Contributors

raijeku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qmeans's Issues

TypeError: '<=' between instances of 'str' and 'int'

Hello.
I'm trying out your module, for which I thank you, and got a curious error that can't figure out on my own:

I'm using IBM Quantum lab online, and this is what I am doing:

X = pd.read_csv('../Datos/bankmarketing-101.csv', sep=';', usecols=['age', 'job', 'marital'])
# Change categorical data to number
X["marital"] = pd.Categorical(X["marital"])
X["marital"] = X["marital"].cat.codes
# Change categorical data to number 
X["job"] = pd.Categorical(X["job"])
X["job"] = X["job"].cat.codes

# Procesamiento
qk_means = QuantumKMeans(dev, n_clusters=3, verbose=True)
qk_means.fit(X)

An then I get the error:

[100 rows x 3 columns]
Iteration 0
Traceback (most recent call last):
  Input In [11] in <cell line: 30>
    qk_means.fit(X)
  File /opt/conda/lib/python3.8/site-packages/qmeans/qkmeans.py:756 in fit
    else: distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([norms[i],cluster_norms[j]])) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])
  File /opt/conda/lib/python3.8/site-packages/qmeans/qkmeans.py:756 in <listcomp>
    else: distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([norms[i],cluster_norms[j]])) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])
  File /opt/conda/lib/python3.8/site-packages/qmeans/qkmeans.py:756 in <listcomp>
    else: distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([norms[i],cluster_norms[j]])) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])
  File /opt/conda/lib/python3.8/site-packages/qmeans/qkmeans.py:194 in distance
    job = execute(qc,backend=backend, shots=shots)
  File /opt/conda/lib/python3.8/site-packages/qiskit/execute_function.py:299 in execute
    experiments = transpile(
  File /opt/conda/lib/python3.8/site-packages/qiskit/compiler/transpiler.py:327 in transpile
    unique_transpile_args, shared_args = _parse_transpile_args(
  File /opt/conda/lib/python3.8/site-packages/qiskit/compiler/transpiler.py:648 in _parse_transpile_args
    basis_gates = _parse_basis_gates(basis_gates, backend)
  File /opt/conda/lib/python3.8/site-packages/qiskit/compiler/transpiler.py:762 in _parse_basis_gates
    if backend_version <= 1:
TypeError: '<=' not supported between instances of 'str' and 'int'```

I don't see any string in the data, also searched the internet for similar problems similar, to no avail. So I ask you: can you see what is that I'm doing wrong?

Thanks in advance.
--
Nicolás.

QiskitError: "Cannot unroll the circuit to the given basis

I'm attempting to run the usage example but I want to use the ibmq_qasm_simulator instead of the aer_simulator_statevector

The code:

backend = provider.get_backend("ibmq_qasm_simulator")
X = pd.DataFrame(np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]]))
qk_means = QuantumKMeans(backend, n_clusters=2, verbose=True)
qk_means.fit(X)
print(qk_means.labels_)

The error message:

Data is:     0  1
0   1  2
1   1  4
2   1  0
3  10  2
4  10  4
5  10  0
Iteration 0
Output exceeds the [size limit](command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?5a07abf9-11ba-4018-b8a5-3504edf05547)---------------------------------------------------------------------------
QiskitError                               Traceback (most recent call last)
Cell In[10], line 4
      2 X = pd.DataFrame(np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]]))
      3 qk_means = QuantumKMeans(backend, n_clusters=2, verbose=True)
----> 4 qk_means.fit(X)
      5 print(qk_means.labels_)

File [~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794](https://file+.vscode-resource.vscode-cdn.net/Users/james/sw/k-means/~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794), in QuantumKMeans.fit(self, X, y, batch)
    792 else: 
    793     if self.map_type == 'probability':
--> 794         distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([norms[i],cluster_norms[j]]),noise_model=self.noise_model) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])
    795     elif self.map_type == 'angle':
    796         distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([1,1]),self.norm_relevance,noise_model=self.noise_model) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])

File [~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794](https://file+.vscode-resource.vscode-cdn.net/Users/james/sw/k-means/~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794), in (.0)
    792 else: 
    793     if self.map_type == 'probability':
--> 794         distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([norms[i],cluster_norms[j]]),noise_model=self.noise_model) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])
    795     elif self.map_type == 'angle':
    796         distances = np.asarray([[distance(point,centroid,self.backend,self.map_type,self.shots,np.array([1,1]),self.norm_relevance,noise_model=self.noise_model) for i, point in X.iterrows()] for j, centroid in normalized_clusters.iterrows()])

File [~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794](https://file+.vscode-resource.vscode-cdn.net/Users/james/sw/k-means/~/sw/k-means/.env/lib/python3.10/site-packages/qmeans/qkmeans.py:794), in (.0)
    792 else: 
    793     if self.map_type == 'probability':
...
    108 unrolled_dag = UnrollCustomDefinitions(
    109     self._equiv_lib, self._basis_gates, target=self._target
    110 ).run(decomposition)

QiskitError: "Cannot unroll the circuit to the given basis, ['u1', 'u2', 'u3', 'u', 'p', 'r', 'rx', 'ry', 'rz', 'cx', 'cy', 'cz', 'csx', 'cp', 'id', 'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 't', 'tdg', 'swap', 'ccx', 'cswap', 'unitary', 'diagonal', 'initialize', 'cu1', 'cu2', 'cu3', 'rxx', 'ryy', 'rzz', 'rzx', 'mcx', 'mcy', 'mcz', 'mcsx', 'mcp', 'mcu1', 'mcu2', 'mcu3', 'mcrx', 'mcry', 'mcrz', 'mcr', 'mcswap', 'multiplexer', 'kraus', 'delay', 'roerror', 'measure']. Instruction reset not found in equivalence library and no rule found to expand."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.