#import / #include
Pull gate definitions from another .qubi file. #include is an exact alias. Pick whichever reads better. Both directives behave identically in the preprocessor and the editor.
#import my-gates.qubi #include shared/oracle.qubi
Filenames must end with .qubi and use only letters, digits, dots, hyphens, and underscores. Trailing // comments on the same line are allowed.
Where files are found
The simulator resolves imports in this order:
- Open editor tabs: any
.qubifile you have loaded in the Qubi Code Editor (matched case-insensitively by filename). - Library cache: files already fetched during this session.
- Server libraries folder:
/simulator/libraries/yourfile.qubion the host.
If the file does not exist, compilation stops with #import filename: file not found on that line. The circuit builder clears instead of showing a half-parsed mess. Fix the path or create the tab before expecting gates from the import.
Editor autocomplete
After you type #import or #include (note the space), the code editor suggests existing .qubi files from your open tabs. The current file is excluded so you do not import yourself. Pick a suggestion or keep typing to filter.
Namespacing (same name in two files)
Every imported library gate/function is also registered under a file prefix: the filename stem, lowercased, with hyphens and other punctuation stripped, then a hyphen and the gate name.
oracleA.qubidefiningOracle→ calloraclea-Oracle(...)(or bareOracle(...)if nothing else claimed that name first).my-gates.qubidefiningFoo→ callmygates-Foo(...).
When two includes define the same name, the first import keeps the bare name; later ones are only reachable with the prefix. Example:
#include teamA.qubi #include teamB.qubi // First import owns the bare name: Oracle(0,1) // Disambiguate with file-stem prefix: teama-Oracle(0,1) teamb-Oracle(0,1)
Autocomplete lists the bare name (with the owning file as the source chip) and extra rows for other libraries’ prefixed forms. Typing a hyphenated prefix (for example teamb-) filters to that qualified call.
Prefixes use the basename only (shared/oracle.qubi and oracle.qubi both become oracle-). Give colliding libraries different filenames if you need distinct prefixes.
Limits and hygiene
- Import depth is capped at 20 nested files.
- Circular imports are rejected with a clear error.
- Imports expand during preprocess, do not put
#importinside agate { }body. - When syncing code → circuit, import lines are validated before preprocess so missing files fail fast.
#include standard/all.qubi, which pulls in standard gates and algorithm functions (Grover, QFT, Deutsch, …). You no longer need legacy #import innovation.qubi; that include is ignored if present.