SingIDBot — Telegram ID Retrieval Bot for OpenClaw Topic Configuration

SETUP GUIDE
Build and deploy SingIDBot — a Telegram bot that retrieves Chat IDs and Topic Thread IDs, with a Singlish personality — on PythonAnywhere.

SingIDBot — Telegram ID Retrieval Bot for OpenClaw Topic Configuration

If you have been working through the OpenClaw Telegram integration guide, you already know that one of the trickiest steps is obtaining the correct Chat ID and Topic Thread ID before you can configure your bot endpoints. Getting those IDs wrong means your bot silently sends messages into the void — no errors, no feedback, just nothing arriving in the right place.

SingIDBot was built specifically to solve that problem. Drop it into any Telegram chat or group, fire the /getids command, and it will instantly report back the Chat ID and — crucially — the message_thread_id for whichever topic the command was sent from. No fiddling with Telegram’s Bot API directly, no JSON parsing, no guesswork.

Beyond the ID retrieval utility, SingIDBot has a second personality: it responds to free-text messages in Singlish — Singapore’s beloved colloquial English creole — cycling through randomised phrases like “Aiyoh, you finally came! Welcome lah!” and “Wah, interesting leh. Tell me more can?” This makes the bot noticeably more fun to test in group chats, and also serves as a practical demonstration of keyword-based message classification in python-telegram-bot v20+.

This guide walks through the complete source code, explains each architectural decision, and then covers deployment on PythonAnywhere including the free-tier network restrictions you will inevitably hit and exactly how to handle them.

Prerequisites
Requirement Details
Python 3.10+ Required for python-telegram-bot v20+ async support. PythonAnywhere provides Python 3.10 on all plans.
python-telegram-bot v20+ The async-native version of the library. Install with pip install python-telegram-bot. Version 20 introduced the Application.builder() pattern used throughout this bot.
Telegram Bot Token Create a new bot via @BotFather on Telegram. Send /newbot, follow the prompts, and copy the token. Keep it secret.
PythonAnywhere account A free Beginner account is sufficient to run and test the bot, but has an important network restriction covered in Section 3. A paid plan removes that restriction entirely.
Section 1 — What SingIDBot Does

The message_thread_id Mechanism

Telegram supergroups can be divided into named Topics, each identified by a message_thread_id. When a message is sent inside a topic, Telegram attaches this integer to the message object. When sent outside any topic, the field is absent entirely — not zero, not null, but genuinely missing.

This is the exact value OpenClaw requires to route notifications to the correct topic thread. SingIDBot’s /getids command reads message_thread_id from the incoming message and reports it in plain text for direct copy-paste into your configuration.

Because the field may be absent, the code uses getattr(update.effective_message, ‘message_thread_id’, None) rather than direct attribute access, which would raise an AttributeError in non-topic contexts.

The Singlish Responder

Any free-text message (not a command) triggers the singlish_chat handler. It classifies the message into greeting, thanks, or default using keyword matching, then picks a random phrase from the corresponding pool. A guard clause returns early if the message starts with / or was sent by the bot itself, preventing an infinite echo loop.

Section 2 — Code Walkthrough

2.1 Logging Setup

Two handlers run simultaneously: a FileHandler writing UTF-8 lines to singidbot.log, and a StreamHandler for the console. On PythonAnywhere you can watch live output in the bash session and audit the full log file afterward.

LOG_FILE = "singidbot.log"
logging.basicConfig(
    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
    level=logging.INFO,
    handlers=[
        logging.FileHandler(LOG_FILE, encoding="utf-8"),
        logging.StreamHandler(),
    ],
)
logger = logging.getLogger(__name__)
Tip: The encoding=”utf-8″ argument is essential if any Telegram usernames contain non-ASCII characters. Without it, a single emoji in a username can crash the logger with a UnicodeEncodeError.

2.2 Singlish Response Bank

SINGLISH_RESPONSES maps category keys to phrase lists. get_singlish_response() uses dict.get() with a “default” fallback so unknown categories never raise a KeyError, and random.choice() picks uniformly from the pool.

SINGLISH_RESPONSES = {
    "greeting": [
        "Wah, you here ah! Come come, sit down lah!",
        "Eh hello! Long time no see, how are you?",
        "Aiyoh, you finally came! Welcome lah!",
        "Oi! Good to see you sia. What can I help you?",
    ],
    "thanks": [
        "Aiyah, no need to thank one lah!",
        "Wah, so polite! Welcome lah, anytime!",
        "No problem one! Next time also can help you.",
        "Eh, paiseh lah - that is what I am here for!",
    ],
    "default": [
        "Hah? Can repeat or not? I blur blur lah.",
        "Wah, interesting leh. Tell me more can?",
        "Aiyoh, I also dunno how to answer you sia.",
        "Got it lah! But I not so sure about that one.",
        "Eh, you very clever leh. I learn from you!",
    ],
}

def get_singlish_response(category):
    pool = SINGLISH_RESPONSES.get(category, SINGLISH_RESPONSES["default"])
    return random.choice(pool)

2.3 log_activity() Async Helper

log_activity() is declared async to match the handler context. It resolves the user’s display identifier to @username or numeric id, and emits a structured log line with a UTC ISO-8601 timestamp.

async def log_activity(user, event_type, metadata):
    user_info = (
        f"@{user.username}" if user and user.username
        else f"id={user.id}" if user
        else "unknown"
    )
    timestamp = datetime.now(timezone.utc).isoformat()
    logger.info(
        "[%s] event=%s user=%s metadata=%s",
        timestamp, event_type, user_info, metadata
    )

2.4 /start and /help Handlers

Both handlers log the event first, then compose and send a reply. /start personalises the greeting using user.first_name with a fallback to “friend”, prepending a random Singlish greeting to make every first interaction slightly different.

async def start(update, context):
    user = update.effective_user
    await log_activity(user, "START", {"chat_id": update.effective_chat.id})
    greeting = get_singlish_response("greeting")
    name = user.first_name if user and user.first_name else "friend"
    welcome_text = (
        f"{greeting}\n\nEh {name}, I am *SingIDBot* lah!\n\nCommands:\n- /start\n- /help\n- /getids"
    )
    await update.message.reply_text(welcome_text, parse_mode="Markdown")

async def help_command(update, context):
    user = update.effective_user
    await log_activity(user, "HELP", {"chat_id": update.effective_chat.id})
    await update.message.reply_text("*SingIDBot Commands* lah!\n/start /getids /help", parse_mode="Markdown")

2.5 /getids Handler

The key line is the getattr call. Telegram only populates message_thread_id when a message arrives inside a topic thread — in a regular chat the attribute simply does not exist. getattr with a None default handles this safely without raising AttributeError.

async def get_ids(update, context):
    user = update.effective_user
    await log_activity(user, "ID_RETRIEVAL", {"chat_id": update.effective_chat.id})
    chat_id = update.effective_chat.id
    topic_id = getattr(update.effective_message, "message_thread_id", None)
    response = f"Chat/Group ID: {chat_id}\n"
    if topic_id is not None:
        response += f"Topic ID: {topic_id}\n(This ID confirms the specific topic thread)"
    else:
        response += "Topic ID: Not available\n(Topics may not be enabled)"
    response += "\nTip: Record these IDs for configuring bot endpoints!"
    await update.message.reply_text(response, parse_mode="Markdown")
    await update.message.reply_text(f"{get_singlish_response('thanks')} Lah!")

2.6 singlish_chat Handler

Registered with filters.TEXT and ~filters.COMMAND. An internal guard also checks if the sender is the bot itself — without this, the bot’s own replies would trigger further replies in an infinite loop. Keyword classification checks thanks before greeting to avoid misclassification on mixed messages.

async def singlish_chat(update, context):
    user = update.effective_user
    await log_activity(user, "MESSAGE", {"text_preview": update.message.text[:50] if update.message else "N/A"})
    if (not update.message or update.message.text.startswith("/") or update.effective_user.id == context.bot.id):
        return
    user_text = update.message.text.lower().strip()
    if any(w in user_text for w in ["thanks", "thank", "appreciate"]):
        category = "thanks"
    elif any(w in user_text for w in ["hello", "hi", "hey", "oi", "wah", "alamak"]):
        category = "greeting"
    else:
        category = "default"
    await update.message.reply_text(get_singlish_response(category))

2.7 error_handler — Two-Tier Approach

Transient network issues (ProxyError, NetworkError, Conflict) are logged at WARNING level as a single line with no stack trace. Genuine bugs fall through to ERROR level with full exc_info traceback so they remain visible and actionable.

async def error_handler(update, context):
    error = context.error
    if isinstance(error, Exception):
        error_name = type(error).__name__
        error_msg = str(error)
        if "ProxyError" in error_msg or "NetworkError" in error_name:
            logger.warning("Network error (transient): %s", error_msg)
        elif "Conflict" in error_name or "terminated by other getUpdates" in error_msg:
            logger.warning("Conflict error (duplicate instance?): %s", error_msg)
        else:
            logger.error("Unhandled exception: %s: %s", error_name, error_msg, exc_info=context.error)

2.8 main() — Builder Chain, Timeouts, Handler Registration

All three timeout axes — connect, read, and write — are set to 30 seconds. Handlers are registered in priority order: specific commands first, then the catch-all text handler, then the error handler last.

def main():
    TOKEN = "YOUR_BOT_TOKEN_HERE"
    application = (
        Application.builder()
        .token(TOKEN)
        .connect_timeout(30)
        .read_timeout(30)
        .write_timeout(30)
        .build()
    )
    application.add_handler(CommandHandler("start", start))
    application.add_handler(CommandHandler("help", help_command))
    application.add_handler(CommandHandler("getids", get_ids))
    application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, singlish_chat))
    application.add_error_handler(error_handler)
    logger.info("--- SingIDBot Initializing ---")
    application.run_polling(allowed_updates=Update.ALL_TYPES)
Section 3 — Deployment on PythonAnywhere

Upload singidbot.py via the Files tab, open a Bash console, and run:

pip install python-telegram-bot --upgrade
python singidbot.py

Free-Tier Proxy Restriction

Free accounts route outbound traffic through a proxy that does not whitelist api.telegram.org. Outbound sendMessage calls can fail with httpx.ProxyError: 503 Service Unavailable. Inbound polling via getUpdates works fine — it is only the reply direction that is intermittently blocked.

In practice across four live sessions totalling over 5 hours, only 2 ProxyErrors occurred in 1800+ polling cycles. The error handler suppresses these to a single WARNING line so the log stays clean.

Options if you need reliable reply delivery: Upgrade to a paid PythonAnywhere plan (removes proxy restrictions entirely), or switch from polling to webhook mode via PythonAnywhere’s WSGI layer (more complex but works on the free tier).

Avoiding Duplicate Instance Conflicts

Telegram only allows one active getUpdates poller per token. Always kill the old process before restarting:

pkill -f singidbot.py
pgrep -a -f singidbot
python singidbot.py
Section 4 — Log Analysis

The bot was tested across four live sessions on PythonAnywhere’s free tier.

Session Duration Key Events Errors
Session 1 ~2 min First run. Hello received; /getids succeeded returning Chat ID 5024469893. 1 ProxyError on reply (full traceback, no error handler yet).
Session 2 ~3 min Error handler added. /help ProxyError suppressed to single WARNING. /getids worked. Singlish replies all succeeded. 1 ProxyError (WARNING only).
Session 3 ~14 min Extended run. Second /help succeeded. 47 consecutive clean polling cycles. 1 ProxyError (WARNING only).
Session 4 ~5 hours 1800+ log lines. Clean polling throughout. No conflicts, no crashes. 2 ProxyErrors total across the entire session.

SingIDBot is production-stable on the free tier. The intermittent ProxyError is a platform constraint, not a code defect, and the error handler keeps it from polluting the log.

Quick Reference
Command What it returns Notes
/start Personalised Singlish greeting and command list. Works in any chat context.
/help List of all available commands. Works in any chat context.
/getids Chat ID and Topic Thread ID (if inside a topic). Must be run inside the target topic to get a valid Thread ID.

✦ This article was generated with the assistance of Claude by Anthropic

Connecting an OpenClaw Bot to a Telegram Group Topic

SETUP GUIDE
Route OpenClaw agent notifications and responses through a private Telegram group using Topics for clean per-bot threading.

Prerequisites
Item Details
OpenClaw with Telegram bot OpenClaw must already be set up and working with a Telegram bot on your phone before proceeding. This guide only covers configuring it to post into a specific group topic.
Telegram account Active account with admin rights on a Telegram group
Telegram group with Topics A Telegram group with the Topics feature enabled
SingIDBot @SingIDBot — a custom bot built by the author of this guide, used to retrieve the chat ID and topic thread ID. Responds in Singlish, so don't be surprised by the personality.
1  ·  Create a Topic for the Bot

With Topics enabled on your group, create a dedicated topic for your OpenClaw bot to keep its messages isolated from other group activity.

Tap the pencil / new topic icon in your group and give it a clear name such as:

OpenClaw-Bot

Note the topic thread ID — you will retrieve this precisely in Step 2 using SingIDBot.

Tip: If the Topics toggle is not visible in your group settings, try adding 4–5 members to the group first. Telegram requires a minimum number of members before the Topics feature becomes available.
2  ·  Get IDs from SingIDBot

SingIDBot (@SingIDBot) returns the exact numeric IDs that OpenClaw needs: the group's chat ID and the topic's thread ID.

  1. Add @SingIDBot to your group and grant it member access.
  2. Navigate into your OpenClaw-Bot topic (not the General topic) before sending the command.
  3. Inside the topic, send: /getids
  4. SingIDBot will reply with a block like this:
Chat ID     : -1001234567890
Thread ID : 42
User ID     : 987654321

Copy the Chat ID and Thread ID. You will pass them to OpenClaw in Step 4.

3  ·  Ask OpenClaw to Build the Config Tool

Rather than editing the .env file manually, ask the OpenClaw agent to write a Python tool that does it for you. The tool only needs the chat ID and topic thread ID — the bot token is already present in the .env from initial setup and does not need to be passed in. Use this prompt in your OpenClaw chat interface:

Create a Python tool called update_telegram_config that accepts chat_id and topic_id as arguments and writes the values of TELEGRAM_CHAT_ID and TELEGRAM_TOPIC_ID into the OpenClaw .env file.

OpenClaw will scaffold the tool, register it, and confirm it is ready to call. Proceed to Step 4 once the agent confirms the tool is available.

4  ·  Run the Tool and Reload OpenClaw

With the IDs from Step 2 in hand, instruct OpenClaw to run the tool using your actual values:

Run update_telegram_config with: chat_id = “-1001234567890” topic_id = “42”

Replace the placeholder values with the IDs from Step 2. After the tool executes, reload OpenClaw so the new environment variables are picked up:

# In your terminal (if running OpenClaw locally) Ctrl+C # stop the current process openclaw # restart
5  ·  Test the Setup

Navigate into the OpenClaw-Bot topic in your Telegram group and post any message. Wait for your OpenClaw bot to reply.

If the group ID and topic ID have been configured correctly, your OpenClaw bot will respond directly inside the topic. If there is no response, double-check the IDs from Step 2 and rerun Step 4.

Note: By default, OpenClaw bots are configured to not respond to any message in a Telegram topic unless the correct group ID and topic ID are added into the config file. A missing or incorrect ID will result in complete silence from the bot.

SingIDBot Quick Reference

@SingIDBot is a custom Telegram bot built by the author of this guide. It does one job well: return the IDs you need for bot configuration. It also speaks Singlish, so expect replies like “Wah, your chat ID here lah” — perfectly normal, just read past the flavour text and grab your numbers.

Command What it returns Notes
/getids Chat ID, Thread ID (topic), and your User ID Must be run inside the target topic to get the correct Thread ID

Also tested on Hermes Agent: The same setup process works with the NousResearch Hermes Agent framework. The update_telegram_config tool and environment variable structure are identical — simply run the same steps with Hermes Agent in place of OpenClaw.
Your agent is now wired to a dedicated Telegram topic. Every notification, response, or alert it sends will land in the OpenClaw-Bot thread, keeping it separate from general group activity. To add more agents or tools later, repeat Steps 1–4 with a new topic and a new set of environment variable names.

✦ This article was generated with the assistance of Claude by Anthropic

Quantum Computing: The Walsh-Hadamard Matrix — Backbone of Grover’s Diffusion Operator

QUANTUM SERIES 2026
The mathematical foundation behind Grover’s diffusion operator — derived from first principles.

In the Grover’s Algorithm — Inversion About the Mean walkthrough, the diffusion operator applies H⊗³ twice per iteration. Every single step is governed by a sign table called the Hadamard Reference. That table is not a lookup shortcut — it is the 8×8 Walsh-Hadamard Transform matrix written out in full. This post derives it from scratch: one qubit, then two, then all three, arriving at the complete matrix and the rule behind every sign in it.


1  ·  The Circuit: Three Qubits, Three Hadamard Gates

We initialise all three qubits in the ground state |0⟩ and route each through its own independent Hadamard gate. There are no two-qubit (entangling) gates here — the circuit is entirely parallel.

Qubit Input Gate Output ket
q₀ |0⟩ H (1/√2)( |0⟩ + |1⟩ )
q₁ |0⟩ H (1/√2)( |0⟩ + |1⟩ )
q₂ |0⟩ H (1/√2)( |0⟩ + |1⟩ )

All three outputs are identical because all three inputs are identical. The structure we need emerges when we take their tensor product.

2  ·  Single-Qubit Hadamard Action

The Hadamard gate H maps the two computational basis states as follows:

Input H |input⟩ Short notation
|0⟩ (1/√2)( |0⟩ + |1⟩ ) |+⟩
|1⟩ (1/√2)( |0⟩ |1⟩ ) |−⟩

In matrix form:

H  =  (1/√2)    +1   +1 
 +1   −1 
Key property: H is its own inverse — H² = I. Every element has magnitude 1/√2, so tensoring three copies multiplies the magnitudes to 1/√8 while the signs follow a precise bitwise pattern.
3  ·  Two-Qubit Tensor Product: q₀ ⊗ q₁

Expanding the tensor product of the first two post-H qubits:

|+⟩ ⊗ |+⟩
  = (1/√2)(|0⟩ + |1⟩) ⊗ (1/√2)(|0⟩ + |1⟩)
  = (1/2)( |0⟩⊗|0⟩ + |0⟩⊗|1⟩ + |1⟩⊗|0⟩ + |1⟩⊗|1⟩ )
  = (1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )
All four two-qubit basis states appear with equal amplitude 1/2. Measurement probability per state: (1/2)² = 25%.
4  ·  Three-Qubit Tensor Product: q₀ ⊗ q₁ ⊗ q₂

Adding the third qubit expands the superposition to all 8 three-bit strings:

|+⟩ ⊗ |+⟩ ⊗ |+⟩
  = (1/√2)³ (|0⟩+|1⟩) ⊗ (|0⟩+|1⟩) ⊗ (|0⟩+|1⟩)
  = (1/√8)( |000⟩ + |001⟩ + |010⟩ + |011⟩
            + |100⟩ + |101⟩ + |110⟩ + |111⟩ )
This is |ψinit — the uniform superposition over all 8 basis states that opens Grover’s algorithm (Phase 0 in the walkthrough). Each state carries amplitude +1/√8 ≈ 0.3535 and measurement probability 1/8 = 12.5%. All signs are positive because we only applied H to |0⟩ inputs — the sign variation appears when H⊗³ acts on states other than |000⟩.
5  ·  The 8×8 Walsh-Hadamard Sign Matrix

When H⊗³ is applied to an arbitrary basis state |j⟩, the result is:

H⊗³ |j⟩  =  (1/√8)   Σᵢ   (−1)popcount(i AND j)   |i⟩

The entry at row i, column j carries sign (−1)popcount(i AND j) divided by √8. The table below shows all 64 signs — green (+) for +1/√8 and red (−) for −1/√8:

H⊗³ |j⟩ →
output |i⟩ ↓
|000⟩ |001⟩ |010⟩ |011⟩ |100⟩ |101⟩ |110⟩ |111⟩
H|000⟩ + + + + + + + +
H|001⟩ + + + +
H|010⟩ + + + +
H|011⟩ + + + +
H|100⟩ + + + +
H|101⟩ + + + +
H|110⟩ + + + +
H|111⟩ + + + +
+  =  amplitude +1/√8 ≈ +0.3535      =  amplitude −1/√8 ≈ −0.3535
6  ·  Why the Sign is (−1)popcount(i AND j)

Because H acts independently on each qubit, H⊗³ is the tensor product of three 2×2 matrices. The entry at row i, column j is simply the product of the three corresponding single-qubit entries:

H⊗³[i, j]  =  H[i₀, j₀]  ×  H[i₁, j₁]  ×  H[i₂, j₂]

Each single-qubit factor equals +1 unless both the k-th bit of i and the k-th bit of j are 1, in which case it equals −1. So the k-th factor contributes a sign of (−1)iₖ·jₖ. Multiplying all three:

sign(i, j)  =  (−1)i₀j₀ + i₁j₁ + i₂j₂  =  (−1)popcount(i AND j)
The rule in plain terms: bitwise AND the row index and the column index, count the 1-bits, check parity. Even count → positive. Odd count → negative.

Quick verification: row H|101⟩, column |011⟩

i (row) j (col) i AND j popcount Sign
101 (= 5) 011 (= 3) 001 1 (odd) − ✓

Matches the matrix in Section 5: row H|101⟩, column |011⟩ is indeed .

7  ·  Connection to Grover’s Diffusion Operator

This matrix is the Hadamard Reference table used throughout the Grover’s Algorithm — Inversion About the Mean post. The diffusion operator D = H⊗³ (2|0⟩⟨0| − I) H⊗³ works in three sub-steps, each directly using this matrix:

Sub-step Operation Grover walkthrough steps
First H⊗³ Maps computational basis → Hadamard basis. Each amplitude spreads across all 8 columns via the sign table. 4.1  ·  6.1  ·  8.1
Phase flip 2|0⟩⟨0|−I: keeps |000⟩ unchanged, negates all other states. This is the inversion-about-the-mean mechanism. 4.2  ·  6.2  ·  8.2
Second H⊗³ Maps back to computational basis using the same sign table (H is self-inverse). Routes constructive interference into the target state. 4.3  ·  6.3  ·  8.3
The bottom line: without the sign structure of the Walsh-Hadamard matrix, neither the uniform superposition (Phase 0) nor the diffusion step (every iteration) would work. The matrix is the silent engine behind Grover’s quadratic speedup.

Quantum Series 2026  ·  Built with Qiskit 1.x

✦ This article was generated with the assistance of Claude by Anthropic

Quantum Computing: Grover’s Algorithm – Inversion About the Mean

Grover’s Algorithm: Exact Mathematical Evolution

Full 3-Qubit Matrix Interference Walkthrough

What is Grover’s Algorithm? Grover’s algorithm is a quantum search procedure that locates a marked item in an unsorted list of N items in O(√N) oracle queries — a quadratic speedup over any classical approach. For N = 8 (3 qubits), this means roughly ⌊π/4 × √8⌋ = 2 optimal iterations before the probability of measuring the target state peaks.

This walkthrough tracks the exact amplitude of every basis state through each gate operation for the 3-qubit case, with target state |101>. All arithmetic is shown so each step can be verified by hand.

Structure of each iteration (Grover operator G):

  • Oracle Uf — Phase-flips the target state: |x> → -|x> if f(x) = 1, otherwise |x> → |x>.
  • Diffusion operator D = H⊗n(2|0><0| − I)H⊗n — Reflects all amplitudes about their mean, amplifying the marked state at the expense of the others.

Key insight: The oracle introduces destructive interference at the target, which the diffusion operator then converts into constructive interference by inverting amplitudes about their mean. Each iteration rotates the state vector by an angle 2θ closer to the target, where sin(θ) = 1/√N.

Circuit Overview — 3 Qubits, Target |101⟩
Init Diffusion 1 Diffusion 2
|0⟩H Uf HZ0H Uf HZ0H M
|0⟩H   H H   H H M
|0⟩H   H H   H H M
Iteration 1 Iteration 2 · optimal
H = Hadamard Uf = Oracle (phase-flips target) Z0 = 2|0⟩⟨0|−I M = Measure

Phase 0: Initialization

Steps 1 & 2: Apply H⊗3 to |000> to create a uniform superposition over all 8 basis states. Because each single-qubit Hadamard maps |0> to (|0>+|1>)/√2, applying all three simultaneously yields equal amplitude 1/√8 ≈ 0.3535 for every state. This is the starting point — every state is equally likely, and the algorithm has no preference yet.

init> = 1/√8 [ |000> + |001> + |010> + |011> + |100> + |101> + |110> + |111> ]

Hadamard Reference (Standard Signs)

The 8×8 Walsh-Hadamard matrix defines the sign pattern when H⊗3 is applied to any basis state. Element (i, j) has sign (−1)popcount(i AND j) — i.e., the number of bit positions where both row state and column state have a 1. The actual amplitude contribution is this sign divided by √8. This table is used in every Hadamard step below: each row corresponds to one input basis state, and its sign pattern determines how it distributes into all 8 output states.

Basis State000001010011100101110111
H|000>++++++++
H|001>++++
H|010>++++
H|011>++++
H|100>++++
H|101>++++
H|110>++++
H|111>++++

Round 1: [Oracle → Diffusion]

Step 3: Oracle Uf — The oracle recognises |101> as the marked state and applies a phase kickback, flipping its amplitude from +1/√8 to −1/√8. All other amplitudes remain unchanged. Physically, this encodes “this is the target” purely in phase — no measurement is made, so the superposition is preserved.

Step 4.1: Round 1 First Hadamard (H)

The diffusion operator begins by mapping from the computational basis back into the Hadamard basis. Each input state |x> with amplitude ax contributes ax/√8 to every output column, with sign given by the reference table. For all non-target states ax = +1/√8, so each cell = (+1/√8)×(Sign/√8) = Sign/8. For the oracle-marked |101>, the amplitude is −1/√8, so the entire row is sign-inverted (highlighted in red). The Net Result row is the vertical sum of all 8 rows for each column.

Source (Post-Oracle)000001010011100101110111
+H|000> (1/√8)+18+18+18+18+18+18+18+18
+H|001> (1/√8)+18-18+18-18+18-18+18-18
+H|010> (1/√8)+18+18-18-18+18+18-18-18
+H|011> (1/√8)+18-18-18+18+18-18-18+18
+H|100> (1/√8)+18+18+18+18-18-18-18-18
-H|101> (-1/√8)-18+18-18+18+18-18+18-18
+H|110> (1/√8)+18+18-18-18-18-18+18+18
+H|111> (1/√8)+18-18-18+18-18+18+18-18
Net Result 4.1+68+28-28+28+28-28+28-28

Step 4.2: Round 1 Phase Flip (Z on non-|000>)

This step implements the 2|0><0|−I operator in the computational basis. In practice it means: keep |000>’s amplitude unchanged, and negate every other state. This is the heart of inversion-about-the-mean: because the |000> column accumulated the largest positive amplitude in Step 4.1 (reflecting the mean of all amplitudes before the first H), flipping everything else relative to it creates the inversion effect that will boost the target in the next step.

State000001010011100101110111
Amp (Post-Z)+68-28+28-28-28+28-28+28

Step 4.3: Round 1 Second Hadamard (H)

The second H maps the Hadamard-basis amplitudes from Step 4.2 back to the computational basis, completing the diffusion operator. Each post-Z amplitude contributes to every output column via the reference sign table, multiplied by 1/√8, giving denominators of 8√8. Summing column |101> yields +208√8 ≈ 0.884 — a dramatic amplification from the initial 0.354 — while all other states settle to +48√8 ≈ 0.177. One iteration is complete.

Source (Post-Z)000001010011100101110111
+H|000> (68)+68√8+68√8+68√8+68√8+68√8+68√8+68√8+68√8
-H|001> (-28)-28√8+28√8-28√8+28√8-28√8+28√8-28√8+28√8
+H|010> (28)+28√8+28√8-28√8-28√8+28√8+28√8-28√8-28√8
-H|011> (-28)-28√8+28√8+28√8-28√8-28√8+28√8+28√8-28√8
-H|100> (-28)-28√8-28√8-28√8-28√8+28√8+28√8+28√8+28√8
+H|101> (28)+28√8-28√8+28√8-28√8-28√8+28√8-28√8+28√8
-H|110> (-28)-28√8-28√8+28√8+28√8+28√8+28√8-28√8-28√8
+H|111> (28)+28√8-28√8-28√8+28√8-28√8+28√8+28√8-28√8
Net Result (R1)+48√8+48√8+48√8+48√8+48√8+208√8+48√8+48√8
Decimal (R1)0.1770.1770.1770.1770.1770.8840.1770.177

Round 2: [Oracle → Diffusion]

Step 5: Oracle Uf — The oracle is applied again to the post-R1 state. |101> now carries a much larger amplitude (+208√8), so the phase flip to −208√8 creates a far more pronounced imbalance. The 7 non-target states each carry only +48√8. This large asymmetry is what will drive even stronger constructive interference in the diffusion step.

Step 6.1: Round 2 First Hadamard (H)

Each amplitude is multiplied by 1/√8 as it spreads across the 8 columns via the reference sign table. The denominator becomes 8√8 × √8 = 64. The 7 uniform states (+48√8) form balanced Walsh-Hadamard rows that cancel perfectly for all non-|000> columns — only the oracle-perturbed |101> row breaks the symmetry, contributing an extra −24 or +24 to each non-zero column (depending on the H sign for that bit pattern). Column |000> is special: all 8 rows contribute positively, giving +864.

Source (Post-Oracle)000001010011100101110111
+H|000> (48√8)+464+464+464+464+464+464+464+464
+H|001> (48√8)+464-464+464-464+464-464+464-464
+H|010> (48√8)+464+464-464-464+464+464-464-464
+H|011> (48√8)+464-464-464+464+464-464-464+464
+H|100> (48√8)+464+464+464+464-464-464-464-464
-H|101> (-208√8)-2064+2064-2064+2064+2064-2064+2064-2064
+H|110> (48√8)+464+464-464-464-464-464+464+464
+H|111> (48√8)+464-464-464+464-464+464+464-464
Net Result 6.1+864+2464-2464+2464+2464-2464+2464-2464

Step 6.2: Phase Flip (Z on non-|000>)

Same operation as Step 4.2: negate every amplitude except |000>. The |000> column retains its +864 value. All other states flip sign, converting e.g. +2464 → −2464. This primes the second Hadamard to route amplitude toward the target state.

State000001010011100101110111
Amp (Post-Z)+864-2464+2464-2464-2464+2464-2464+2464

Step 6.3: Round 2 Second Hadamard (H)

The final H of the diffusion operator maps the post-Z amplitudes back to the computational basis. Each amplitude propagates through the Hadamard sign table with denominator 64√8. Column |101> receives a constructive sum of +17664√8 ≈ 0.972 — near-certain success. The non-target states all land at −1664√8 ≈ −0.088, where the negative sign carries no measurement consequence. This is the optimal stopping point for 3-qubit Grover search: stopping here gives the highest possible P(|101>).

Source (Post-Z)000001010011100101110111
+H|000> (864)+864√8+864√8+864√8+864√8+864√8+864√8+864√8+864√8
-H|001> (-2464)-2464√8+2464√8-2464√8+2464√8-2464√8+2464√8-2464√8+2464√8
+H|010> (2464)+2464√8+2464√8-2464√8-2464√8+2464√8+2464√8-2464√8-2464√8
-H|011> (-2464)-2464√8+2464√8+2464√8-2464√8-2464√8+2464√8+2464√8-2464√8
-H|100> (-2464)-2464√8-2464√8-2464√8-2464√8+2464√8+2464√8+2464√8+2464√8
+H|101> (2464)+2464√8-2464√8+2464√8-2464√8-2464√8+2464√8-2464√8+2464√8
-H|110> (-2464)-2464√8-2464√8+2464√8+2464√8+2464√8+2464√8-2464√8-2464√8
+H|111> (2464)+2464√8-2464√8-2464√8+2464√8-2464√8+2464√8+2464√8-2464√8
Net Result (R2)-1664√8-1664√8-1664√8-1664√8-1664√8+17664√8-1664√8-1664√8
Decimal (R2)-0.088-0.088-0.088-0.088-0.088+0.972-0.088-0.088
Success Probability: P(101) = |0.9724|2 ≈ 94.5%

Round 3: [Oracle → Diffusion] (The Overcooking Effect)

Step 7: Oracle Uf — With P(|101>) at 94.5%, one more iteration is one too many. The oracle again flips |101>’s amplitude: +17664√8 → −17664√8. The 7 non-target states each remain at −1664√8. The state vector has been rotated 2θ past its peak, and a third diffusion step will push it further away from the target, not closer.

Step 8.1: Round 3 First Hadamard (H)

The denominator grows to 512 (= 64√8 × √8). All 8 input amplitudes are now negative (after the oracle flip, |101> is −17664√8 and the rest are −1664√8), so the |000> column accumulates a strongly negative sum (−288512). The non-|000> columns are dominated by the large −|101> row contribution, which is sign-inverted from the reference table and therefore contributes ±176512. The net result is a lopsided distribution that the phase flip will convert into a push away from the target.

Source (Post-Oracle)000001010011100101110111
-H|000> (-1664√8)-16512-16512-16512-16512-16512-16512-16512-16512
-H|001> (-1664√8)-16512+16512-16512+16512-16512+16512-16512+16512
-H|010> (-1664√8)-16512-16512+16512+16512-16512-16512+16512+16512
-H|011> (-1664√8)-16512+16512+16512-16512-16512+16512+16512-16512
-H|100> (-1664√8)-16512-16512-16512-16512+16512+16512+16512+16512
-H|101> (-17664√8)-176512+176512-176512+176512+176512-176512+176512-176512
-H|110> (-1664√8)-16512-16512+16512+16512+16512+16512-16512-16512
-H|111> (-1664√8)-16512+16512+16512-16512+16512-16512-16512+16512
Net Result 8.1-288512+160512-160512+160512+160512-160512+160512-160512

Step 8.2: Round 3 Phase Flip (Z on non-|000>)

The |000> amplitude (−288512) is preserved. All other amplitudes flip sign. Notice that after R2 the non-target states had small negative amplitudes; after the phase flip here they become positive (+160512), while the target column was −160512 and now becomes +160512 as well — the diffusion has lost its asymmetry and will no longer strongly favour |101>.

State000001010011100101110111
Amp (Post-Z)-288512-160512+160512-160512-160512+160512-160512+160512

Step 8.3: Round 3 Second Hadamard (H)

The second H maps amplitudes back to the computational basis with denominators of 512√8. The large negative |000> amplitude now spreads destructive interference broadly, while the relatively uniform positive amplitudes for the remaining states partially cancel in the |101> column. The result is +832512√8 = +138√8 ≈ +0.575 for |101> and −448512√8 = −78√8 ≈ −0.309 for all non-target states. P(|101>) has fallen to ~33%, demonstrating that iterating past the optimal count hurts. Importantly, |101> still leads every other state by 3×, so a single extra iteration only partially degrades the result — it has not catastrophically lost the solution.

Source (Post-Z)000001010011100101110111
-H|000> (-288512)-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8
-H|001> (-160512)-160512√8+160512√8-160512√8+160512√8-160512√8+160512√8-160512√8+160512√8
+H|010> (160512)+160512√8+160512√8-160512√8-160512√8+160512√8+160512√8-160512√8-160512√8
-H|011> (-160512)-160512√8+160512√8+160512√8-160512√8-160512√8+160512√8+160512√8-160512√8
-H|100> (-160512)-160512√8-160512√8-160512√8-160512√8+160512√8+160512√8+160512√8+160512√8
+H|101> (160512)+160512√8-160512√8+160512√8-160512√8-160512√8+160512√8-160512√8+160512√8
-H|110> (-160512)-160512√8-160512√8+160512√8+160512√8+160512√8+160512√8-160512√8-160512√8
+H|111> (160512)+160512√8-160512√8-160512√8+160512√8-160512√8+160512√8+160512√8-160512√8
Net Result (R3)-448512√8-448512√8-448512√8-448512√8-448512√8+832512√8-448512√8-448512√8
Simplified (R3)-78√8-78√8-78√8-78√8-78√8+138√8-78√8-78√8
Decimal (R3)-0.309-0.309-0.309-0.309-0.309+0.575-0.309-0.309

⚠ Overcooking Confirmed — But Not Catastrophic

The state vector has rotated past the optimal angle. P(|101>) drops from 94.5% (R2) to 33.0% — a significant fall, but |101> still has more than double the probability of any other state. The algorithm has not “lost” the answer; it has merely de-amplified it. Note also that the target amplitude is still positive (+0.575) — the vector has not crossed zero, it has simply overshot past the maximum. The 33.0% comes directly from the Born rule: P(|101>) = |amplitude|² = |+0.575|² ≈ 0.330.

Say Goodbye to Finder. Meet Marta.

— macOS Productivity

Say Goodbye to Finder.
Meet Marta.

Why the dual-pane Marta file manager is the upgrade your Mac workflow has been waiting for.

macOS Finder has served Mac users faithfully since 1984 — but its age is showing. For anyone who regularly moves files between folders, manages projects with complex directory structures, or simply wants a more keyboard-friendly workflow, Finder’s single-pane design quickly becomes a bottleneck. Marta is a modern, native macOS file manager that addresses every one of these frustrations head-on.

Best of all? It’s free.

🗂 What is Marta?

Marta is a dual-pane, keyboard-driven file manager built exclusively for macOS. Developed by Yan Zhulanow, it borrows the powerful two-panel paradigm from classic file managers like Total Commander and Midnight Commander — but wraps it in a clean, native macOS interface. It feels right at home on your Mac while giving you superpowers that Finder simply cannot match.

It is highly customisable, supports themes, and even has its own plugin and scripting ecosystem. But even out of the box, the difference is immediately noticeable.

⚙️ How to Install Marta

Getting Marta up and running takes under two minutes. You have two options:

1
Option A — Direct Download (Recommended) Head to the official Marta website and download the latest release directly.
→ marta.sh
2
Option B — Install via Homebrew If you use Homebrew, install Marta with a single terminal command:
brew install –cask marta
3
Move to Applications & Launch If you used the .dmg file, drag Marta into your Applications folder and open it. macOS may ask you to confirm — click Open.
4
Grant Full Disk Access (Optional but Recommended) Go to System Settings → Privacy & Security → Full Disk Access and toggle Marta on. This ensures no folder is off-limits.

✨ Why Marta Beats Finder

Here are the features that make Marta a genuine step-change in your file management experience:

🪟

Dual-Pane Navigation — The Game Changer

The single biggest advantage Marta has over Finder is its side-by-side dual-pane view. Your screen is split into two independent file panels, each showing a different folder. You can see your source and destination simultaneously — copy or move files between them without ever losing your place or juggling multiple Finder windows.

Marta — Dual Pane View
📁 ~/Documents/Projects
📂 report-2024
📄 summary.pdf
📄 data.csv
📂 archive
📁 ~/Desktop/Submissions
📂 week-01
📂 week-02
📄 notes.txt
📄 README.md

For power users — developers, academics, content creators — this alone is worth the switch. No more shuffling windows. No more losing track of where you’re copying to.

📁

Create New Folders in Seconds

In Finder, creating a new folder means right-clicking and hunting through a context menu. In Marta, it’s a single keyboard shortcut — press it and a new folder appears inline, ready to be named. No mouse required, your workflow never breaks stride.

New Folder shortcut: + + N → New folder created inline
⌨️

Fully Keyboard-Driven

Navigate, open, rename, copy, move, and delete files without ever touching the mouse. Marta’s keyboard-first design means experienced users can fly through file operations far faster than any GUI-only workflow allows.

🗃️

Tabs & Bookmarks

Keep multiple folder locations open as tabs within each panel. Bookmark your most-used directories and jump to them instantly — particularly powerful for large project hierarchies.

🎨

Themeable & Configurable

Marta supports custom themes and a powerful configuration file (conf.marco). You can remap shortcuts, add plugins, and tailor the entire interface to match your exact preferences.

💡

Pro tip: You don’t have to remove Finder — it remains the system default for things like the Desktop and disk operations. Simply use Marta as your primary navigation tool for day-to-day file work, and enjoy the best of both worlds.

🏁 The Verdict

Marta won’t replace Finder for every macOS task — but as a daily driver for navigating, organising, and moving files, it is simply in a different league. The dual-pane view alone transforms how you work with files, and features like instant folder creation and keyboard navigation make it feel like a tool built for people who actually use their computer seriously.

If you’ve ever felt frustrated waiting on Finder’s slow animations, losing track of copy destinations, or clicking through five menus just to create a folder — give Marta five minutes. You won’t go back.

macOS Productivity File Manager Marta Workflow

Written for macOS power users · Marta is free & open-source

marta.sh →

✦ This article was generated with the assistance of Claude by Anthropic

Dario Amodei — The Adolescence of Technology

https://www.darioamodei.com/essay/the-adolescence-of-technology

In “The Adolescence of Technology,” Anthropic CEO Dario Amodei argues that humanity is entering a high-stakes “technological puberty” with the imminent arrival of expert-level AI. He outlines a pragmatic strategy to counter existential risks—ranging from biological threats to digital authoritarianism—stressing that through surgical regulation and rigorous safety engineering, we can navigate this dangerous transition toward a future of immense global benefit.

The Cost of Garbage in Quantum Computing

The Hidden Witness

Why You Must Clean Up “Junk Bits” with Uncomputation

1. The “Observer” Effect

In quantum computing, anything that “knows” what a qubit is doing acts as a Witness. Leftover data (Junk Bits) on an ancilla qubit act as witnesses, destroying the interference your algorithm needs to work.

Case A: Ideal (No Junk)

H
H
|0>
|0>

100% Interference

Case B: Broken (With Junk)

H
+
H
|0>
|0>
?
|junk>

Random 50/50 Noise

2. Mathematical Working

Ideal Case: (1/2) ( |0> + |1> + |0> – |1> ) = |0>
(Identical paths cancel perfectly.)

Junk Case: (1/2) ( |00> + |10> + |01> – |11> )
(Terms cannot cancel because the ancilla bit is different. Interference is destroyed.)

3. The Solution: Uncomputation

To restore interference, we follow the Compute-Copy-Uncompute pattern. This resets our ancilla to |0> and removes the “witness.”

Input |x>
Ancilla |0>
Target |0>
COMPUTE
+
UNCOMPUTE
|x> (Clean)
|0> (Clean)
|f(x)> (Result)

4. Qiskit Implementation

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3)
qc.h(0) 
qc.cx(0, 1) # COMPUTE: Create Junk on q1
qc.cx(1, 2) # COPY Result to q2
qc.cx(0, 1) # UNCOMPUTE: Clean Junk back to |0>
qc.h(0)     # Interference Restored!

qc.measure_all()
counts = AerSimulator().run(transpile(qc, AerSimulator())).result().get_counts()
print(f"Resulting state: {counts}")

Built with Qiskit 1.x • Quantum Series 2025

Reversible Computation in Quantum Computing

Reversible Computation in Quantum Computing

Mastering Reversibility, Ancilla Bits, and Unitary Logic

1. The Necessity of Reversibility

In classical logic, gates like AND are inherently irreversible. Because they compress two input bits into a single output bit, information is physically destroyed. For example, if an AND gate outputs ‘0’, you cannot distinguish if the original inputs were (0,0), (0,1), or (1,0). This “many-to-one” mapping results in information loss that manifests as heat dissipation.

In quantum computing, thermodynamics and the laws of physics require all operations to be Unitary (UU = I). This means every quantum gate must be a 1-to-1 (bijective) mapping; no information is ever lost, and the entire computation can be run in reverse to recover the initial state.

AND
Out: 0

The Logic Gap: If the output is 0, the input could be (0,0), (0,1), or (1,0). The path back is lost.

2. Ancilla Bits & Uncomputation

Because we cannot erase information, we use Ancilla bits as temporary “scratch space.” However, if these qubits are left in an arbitrary state, they remain entangled with the computation. Uncomputation (running gates in reverse) resets them to |0>, “cleaning” the quantum workspace.

The Toffoli Gate (CCX)

The Toffoli gate is reversible because its mapping is bijective. No two inputs result in the same output.

+
In: A
In: B
In: C
Input (A, B, C) Output (A, B, C ⊕ AB) Status
0, 0, 00, 0, 0Unique
1, 1, 01, 1, 1Flipped (AND)
1, 1, 11, 1, 0Flipped Back

The Fredkin Gate (CSWAP)

The Fredkin gate is a controlled-swap operation. It swaps the states of the two target qubits (T1 and T2) if and only if the control qubit (C) is in the state |1>. It is conservative, meaning it preserves the Hamming weight (number of 1s) from input to output.

Because it is a universal gate, we can simulate all standard classical logic by fixing certain inputs:

  • NOT: Set T1=0, T2=1. Output T2 becomes NOT C.
  • AND: Set T2=0. Output T2 becomes C AND T1.
  • OR: Set T1=B, T2=1. Output T1 becomes C OR B.
In: C
In: T1
In: T2

3. Mathematics: Unitary vs. Hermitian

Proof: Is Pauli-Y Unitary?

Y =
0i
i0
Y =
0i
i0

Pauli-Y is Unitary (YY = I). Because Y = Y, it is also Hermitian.

Unitary but NOT Hermitian: The S Gate

S =
10
0i
S =
10
0i

Since SS, you must apply the S-Dagger gate to reverse an S rotation.

4. Qiskit Verification

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3)
qc.x([0, 1]) # Controls to |1>

# Toffoli is Hermitian (U = U†), so applying it twice cleans the ancilla
qc.ccx(0, 1, 2) # Calculation step
qc.ccx(0, 1, 2) # Uncomputation step

qc.measure_all()
counts = AerSimulator().run(transpile(qc, AerSimulator())).result().get_counts()
print(f"Resulting state: {counts}") # Expect {'011': 1024}
            

Built with Qiskit 1.x • Quantum Series 2025