[
https://issues.apache.org/jira/browse/MAHOUT-468?focusedWorklogId=943846&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-943846
]
ASF GitHub Bot logged work on MAHOUT-468:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 14/Nov/24 22:07
Start Date: 14/Nov/24 22:07
Worklog Time Spent: 10m
Work Description: andrewmusselman commented on code in PR #472:
URL: https://github.com/apache/mahout/pull/472#discussion_r1842944998
##########
examples/Optimization_Example.ipynb:
##########
@@ -0,0 +1,144 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 2,
+ "cells": [
+ {
+ "cell_type": "code",
+ "source": [
+ "# pip install git+https://github.com/apache/mahout.git@main"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "lNDTZhztd2dp",
+ "outputId": "ea3b9e41-43a8-44e7-9daf-e62e71d93143"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Quantum Circuit Parameterization and Optimization\n",
+ "\n",
+ "In this notebook, we'll explore how to create parameterized quantum
circuits using the QuMat framework. This feature allows us to bind values to
parameters at execution time, paving the way for optimization tasks in quantum
computing.\n",
+ "\n",
+ "## Overview\n",
+ "\n",
+ "1. **Parameter Handling**: We will use symbols to represent parameters in
quantum gates, allowing these parameters to be updated during optimization.\n",
+ "2. **Circuit Execution with Binding**: We will bind parameter values to a
circuit prior to its execution, a critical step in parameter optimization
routines.\n",
+ "3. **Simple Optimization Loop**: We'll implement a basic optimization
loop that updates parameters based on a cost function.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Step 1: Setting Up\n",
+ "\n",
+ "We start by setting up the backend configuration and initializing the
QuMat framework. This framework interfaces with quantum computing libraries
like Qiskit or Cirq to manage the underlying quantum computations.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from qumat.qumat import QuMat\n",
+ "\n",
+ "# Configure the backend to use Qiskit with a simulator\n",
+ "backend_config = {\n",
+ " 'backend_name': 'qiskit',\n",
+ " 'backend_options': {'simulator_type': 'qasm_simulator', 'shots':
1024}\n",
+ "}\n",
+ "\n",
+ "# Create an instance of QuMat\n",
+ "qumat_instance = QuMat(backend_config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Step 2: Creating a Parameterized Quantum Circuit\n",
+ "\n",
+ "We create a simple quantum circuit with one qubit and apply parameterized
RX, RY, and RZ gates. The parameters will be defined symbolically, allowing
them to be replaced with actual values during execution.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Create a quantum circuit with 1 qubit\n",
+ "qumat_instance.create_empty_circuit(1)\n",
+ "\n",
+ "# Apply parameterized RX, RY, and RZ gates\n",
+ "qumat_instance.apply_rx_gate(0, 'theta')\n",
Review Comment:
If this runs for you I'm good approving; I'll make a new issue to add these
def'ns later.
Issue Time Tracking
-------------------
Worklog Id: (was: 943846)
Time Spent: 1h 20m (was: 1h 10m)
> Performance of RowSimilarityJob is not good
> -------------------------------------------
>
> Key: MAHOUT-468
> URL: https://issues.apache.org/jira/browse/MAHOUT-468
> Project: Mahout
> Issue Type: Test
> Affects Versions: 0.4
> Reporter: Han Hui Wen
> Priority: Major
> Attachments:
> RowSimilarityJob-CooccurrencesMapper-SimilarityReducer.jpg
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> I have done a test ,
> Preferences records: 680,194
> distinct users: 23,246
> distinct items:437,569
> SIMILARITY_CLASS_NAME=SIMILARITY_COOCCURRENCE
> maybePruneItemUserMatrixPath:16.50M
> weights:13.80M
> pairwiseSimilarity:18.81G
> Job RowSimilarityJob-RowWeightMapper-WeightedOccurrencesPerColumnReducer:used
> 32 sec
> Job RowSimilarityJob-CooccurrencesMapper-SimilarityReducer:used 4.30 hours
> I think the reason may be following:
> 1) We used SequenceFileOutputFormat,it cause job can only be run by n ( n=
> Hadoop node counts ) mappers or reducers concurrently.
> 2) We stored redundant info.
> for example :
> the output of CooccurrencesMapper:
> (ItemIndexA,similarity),(ItemIndexA,ItemIndexB,similarity)
> 3) Some frequently used code
> https://issues.apache.org/jira/browse/MAHOUT-467
> 4) allocate many local variable in loop (need confirm )
> In Class DistributedUncenteredZeroAssumingCosineVectorSimilarity
> @Override
> public double weight(Vector v) {
> double length = 0.0;
> Iterator<Element> elemIterator = v.iterateNonZero();
> while (elemIterator.hasNext()) {
> double value = elemIterator.next().get(); //this one
> length += value * value;
> }
> return Math.sqrt(length);
> }
> 5) Maybe we need control the size of cooccurrences
--
This message was sent by Atlassian Jira
(v8.20.10#820010)