Skip to content

Commit 14cf87d

Browse files
authored
Add a .geminiignore file and improve the Gemini style guide (#1004)
This adds a `.geminiignore` file to make Gemini CLI ignore a variety of files that are not useful for it to look into. This PR also adds more information to the `.gemini/styleguide.md` file.
1 parent a67d1b3 commit 14cf87d

3 files changed

Lines changed: 181 additions & 63 deletions

File tree

.gemini/styleguide.md

Lines changed: 99 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
This style guide for Gemini outlines the coding conventions for this project.
44

5-
## General guidance
5+
## Introduction and goals
66

7-
### Overall principles
7+
### Overall goals
88

99
* _Readability_: Code must be easy for humans to understand. Prefer clarity
1010
over cleverness. Write elegant, well-structured code.
@@ -16,39 +16,68 @@ This style guide for Gemini outlines the coding conventions for this project.
1616

1717
* _Performance_: While readability is paramount, code should be efficient.
1818

19-
### Overall development approach
19+
### Overall software engineering principles
2020

21-
* Code should be modular and adhere to language idioms and best practices.
21+
* Write modular code that follows language idioms and best practices.
2222

23-
* Data obtained from the user or read from a file should be validated.
24-
Identify and guard against potential vulnerabilities in data handling or
25-
input validation.
23+
* Prioritize numerical stability and accuracy. Keep in mind the limitations of
24+
floating-point arithmetic (e.g., float, double).
2625

27-
* When new functions, classes, and files are introduced, they should also
28-
have corresponding tests. Existing tests must continue to pass (or be
29-
updated) when changes are introduced, and code should be covered by tests.
26+
* Strive for performance through memory efficiency. Watch out for bottlenecks
27+
due to memory access. Design data structures and algorithms to promote data
28+
locality. Access memory sequentially (e.g., iterating through a
29+
`std::vector`) to maximize cache hits.
3030

31-
* Test coverage must be high. We don't require 100% coverage, but any
32-
uncovered code must be annotated appropriate directives (for example,
33-
`# pragma: no cover` in Python).
31+
* Design for vectorization and parallelism. Structure loops and data access
32+
patterns to be friendly to compiler vectorization (SIMD). Avoid complex
33+
control flow (if/else) inside tight loops where possible.
3434

35-
* Tests must be independent and must not rely on the state of other tests.
36-
Setup and teardown functions should be used to create a clean environment
37-
for each test run. External dependencies (e.g., databases, network services,
38-
file system) must be mocked to ensure the test is isolated to the unit under
39-
test.
35+
* Validate all user and file-based data to guard against security
36+
vulnerabilities.
4037

41-
* Make sure to cover edge cases: write tests for invalid inputs, null values,
42-
empty arrays, zero values, and off-by-one errors.
38+
* New code requires new tests. Ensure existing tests continue to pass or are
39+
updated when making changes.
4340

44-
* Use asserts in tests intelligently. Test assertions should be specific:
45-
instead of just asserting `true`, assert that a specific value equals an
46-
expected value. Provide meaningful failure messages.
41+
* Thoroughly test for edge cases, including invalid inputs, null values, empty
42+
arrays, and off-by-one errors.
4743

48-
### Overall code format conventions
44+
* Keep tests independent. Use setup and teardown functions for clean
45+
environments and mock all external dependencies.
4946

50-
Quantum AI projects generally follows Google coding conventions, with a few
51-
changes. The following Google style guides are the starting points:
47+
## Development workflow
48+
49+
### Before you start
50+
51+
* **CRITICAL**: before changing any file, first ask the user if they want to
52+
create a git branch for the work you are about to do.
53+
54+
### File naming conventions
55+
56+
* Regular file names should be in all lower case, using underscores as word
57+
separators as needed. The names should indicate the purpose of the code in
58+
the file, while also be kept as short as possible without compromising
59+
understandability.
60+
61+
* Test files are usually named after the file they test but with a name
62+
ending in `_test.py` or `_test.cc`. For example, `something.py` would have
63+
tests in a file named `something_test.py`.
64+
65+
### File structure conventions
66+
67+
* Files must end with a final newline, unless they are special files that do
68+
not normally have ending newlines.
69+
70+
### Git commit conventions
71+
72+
* Use `git commit` to commit changes to files as you work. Each commit should
73+
encompass a subportion of your work that is conceptually related.
74+
75+
* Each commit must have a title and a description.
76+
77+
### Code style conventions
78+
79+
Follow these Google coding conventions, with some project-specific conventions
80+
noted below.
5281

5382
* [Google C++ Style Guide](
5483
https://google.github.io/styleguide/cppguide.html)
@@ -63,8 +92,7 @@ changes. The following Google style guides are the starting points:
6392
https://google.github.io/styleguide/shellguide.html)
6493

6594
To learn this project's conventions for line length, indentation, and other
66-
details of coding style, please inspect the following configuration files (if
67-
present at the top level of this project repository):
95+
details of coding style, please inspect the following configuration files:
6896

6997
* [`.editorconfig`](../.editorconfig) for basic code editor configuration
7098
(e.g., indentation and line length) specified using the
@@ -83,14 +111,14 @@ present at the top level of this project repository):
83111

84112
* [`.yamllint.yaml`](../.yamllint.yaml) for YAML files.
85113

86-
### Overall code comment conventions
114+
### Code comment conventions
87115

88-
Every source file must begin with a header comment with the copyright and
89-
license. We use the Apache 2.0 license. Here is an example of the required file
90-
header for a Python language code file:
116+
Every source code file longer than 2 lines must begin with a header comment with
117+
the copyright and license. We use the Apache 2.0 license. Here is an example for
118+
Python code:
91119

92120
```python
93-
# Copyright 2025 Google LLC
121+
# Copyright 2026 Google LLC
94122
#
95123
# Licensed under the Apache License, Version 2.0 (the "License");
96124
# you may not use this file except in compliance with the License.
@@ -123,6 +151,28 @@ For comments in other parts of the files, follow these guidelines:
123151

124152
This section outlines coding conventions for Python code in this project.
125153

154+
### Setting up a Python environment for development
155+
156+
To set up a Python development environment, do the following:
157+
158+
```shell
159+
python3 -m venv venv
160+
source venv/bin/activate
161+
pip install -U pip
162+
```
163+
164+
If there is a `dev-requirements.txt` file in the directory, run
165+
166+
```shell
167+
pip install -r requirements.txt -r dev-requirements.txt
168+
```
169+
170+
otherwise, run
171+
172+
```shell
173+
pip install -r requirements.txt --group dev
174+
```
175+
126176
### Python naming conventions
127177

128178
This project follows some nomenclature rules and conventions in order to
@@ -137,7 +187,7 @@ naming, we can reduce cognitive load on human users and developers.
137187

138188
* _Functions_: Use lowercase with underscores (snake_case). Examples:
139189
`calculate_total()`, `process_data()`. Internal functions are prefixed with
140-
an understore (`_`).
190+
an underscore (`_`).
141191

142192
* _Classes_: Use CapWords (CamelCase). Examples: `UserManager`,
143193
`PaymentProcessor`.
@@ -164,7 +214,7 @@ naming, we can reduce cognitive load on human users and developers.
164214
amplitudes. If a function expects a NumPy array of amplitudes, its type
165215
annotation should be `np.ndarray`.
166216

167-
### Python docstrings and documentation
217+
### Python docstrings and documentation
168218

169219
This project uses [Google style doc strings](
170220
http://google.github.io/styleguide/pyguide.html#381-docstrings) with a Markdown
@@ -212,7 +262,8 @@ def some_function(a: int, b: str) -> float:
212262
### Python formatting
213263

214264
Note: the Python code uses 88-column line widths, which is the default used by
215-
code the formatters `black` and `flynt`. (The C++ files use 80.)
265+
code the formatter `black` but not the [Google Python Style Guide](
266+
https://google.github.io/styleguide/pyguide.html). (The latter use 80.)
216267

217268
The following programs can be used to perform some automated formatting.
218269

@@ -236,7 +287,7 @@ where possible, especially on public classes and functions to serve as
236287
documentation, but also on internal code so that the `mypy` type checker can
237288
help catch coding errors.
238289

239-
### Python linting
290+
### Linting Python code
240291

241292
Python files:
242293

@@ -246,7 +297,7 @@ Python files:
246297

247298
* `pylint -j0 .` will run `pylint` on all Python files.
248299

249-
### Python testing
300+
### Testing Python code
250301

251302
Unit and integration tests can be run for the Python portions of this project
252303
using the following command:
@@ -279,7 +330,7 @@ This section outlines coding conventions for C++ code in this project.
279330
* A computational basis state (say, $|0000\rangle$) is typically
280331
referred to as a `bitstring`.
281332

282-
### C++ formatting
333+
### Formatting C++ code
283334

284335
Note: the C++ code files use 80-column line widths. (The Python files use 88.)
285336

@@ -288,7 +339,7 @@ Note: the C++ code files use 80-column line widths. (The Python files use 88.)
288339

289340
* `clang-format -i PATH/TO/FILE` will reformat the file.
290341

291-
#### C++ testing
342+
#### Testing C++ code
292343

293344
If you only want to run tests for the core C++ libraries, use this command:
294345

@@ -299,16 +350,22 @@ bazel test tests:all
299350
To build tests without running them, instead use:
300351

301352
```shell
302-
bzel build tests:all
353+
bazel build --config=verbose tests:all
303354
```
304355

305356
## Shell script-specific guidance
306357

307358
Shell scripts should use Bash.
308359

309-
### Shell script formatting
360+
### Formatting shell scripts
310361

311362
Use the [Google Shell Style Guide](
312363
https://google.github.io/styleguide/shellguide.html) with the following changes:
313364

314365
* Use indentation of 4 spaces, not 2.
366+
367+
## TOML file-specific guidance
368+
369+
### Formatting `.toml` files
370+
371+
We use indentation of 4 spaces, not 2.

.geminiignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Summary: tell Gemini CLI what it should or should not ignore. Takes precedence
16+
# over .gitignore (which Gemini CLI also reads), thus can be used to un-ignore
17+
# files that shouldn't be committed to git yet should be visible to Gemini. Also
18+
# used to ignore things usually in people's global .gitignore files.
19+
20+
# Not in .gitignore because it's a git submodule. Tell Gemini to ignore it.
21+
/tests/googletest/

.gitignore

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,68 @@
1-
# Generated files
2-
*.o
3-
*.a
4-
*.so
5-
*.x
6-
*.mod
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
714

8-
# Python cache
9-
__pycache__
10-
.ipynb_checkpoints
15+
# Summary: tell git what to ignore in the qsim source tree.
1116

12-
# Build
13-
/build
14-
*.egg-info
17+
# Bazel files.
18+
/bazel-*
1519

16-
# Bazel output
17-
bazel-*
20+
# Eigen is downloaded by our build files.
21+
eigen/
1822

19-
.idea/*
23+
# Jupyter-specific items.
24+
*/.ipynb_checkpoints/
25+
.ipynb_checkpoints
26+
ipython_config.py
2027

21-
# Eigen library
22-
eigen
28+
# Python-related items.
29+
*.coverage
30+
*.coverage.*
31+
*.egg
32+
*.egg-info/
33+
*.py,cover
34+
*.py[cod]
35+
.cache/
36+
.dmypy.json
37+
.mypy_cache/
38+
.pytest_cache/
39+
.pytype/
40+
.ruff_cache/
41+
__pycache__/
42+
build/
43+
dist/
44+
dmypy.json
45+
wheelhouse/
2346

24-
# vscode
25-
.vscode/*
47+
# Python virtual environments (from instructions given to people).
48+
CirqDevEnv
49+
venv
50+
51+
# Generated files.
52+
*.o
53+
*.a
54+
*.so
55+
*.x
56+
*.mod
2657

27-
# Bazel files
28-
/bazel-*
58+
# Miscellaneous common editor backup files and temp files.
59+
*.bak
60+
*.swp
61+
*.tmp
62+
*~
63+
.\#*
64+
.idea/
65+
.vs
66+
.vscode/
67+
.~*~
68+
\#*\#

0 commit comments

Comments
 (0)